Bundle Size Optimization and Tree Shaking
Techniques bundlers use to eliminate unused code from a final JavaScript bundle, relying heavily on ES modules' static import/export structure.
Tree shaking is the process by which a module bundler statically analyzes an application's import/export graph and eliminates code that's provably never actually used, producing a smaller final bundle than simply concatenating every imported file's entire contents together regardless of what's actually referenced. It's one of the most impactful build-time optimizations for real-world bundle size, and it relies specifically on a structural property of ES modules that older module systems didn't reliably provide.
Tree shaking is like a moving company that, instead of packing an entire warehouse's full inventory onto the truck because you rented space there, only loads the specific labeled boxes you've actually indicated you need at your new place, based on a complete, itemized list you provided upfront (the static import graph) — nothing gets shipped that wasn't explicitly itemized as needed.