tree shaking
Removing code that is exported but never imported from the final bundle, so less code is shipped.
In more detail
Bundlers can do it for ES modules because their imports are known before the code runs, and it works best when a package declares that its files have no side effects. It matters most for code sent to browsers.
Related terms
- sideEffects — A package.json field that tells bundlers whether importing a file does anything besides defining exports.
- bundler — A build tool, such as webpack, Rollup or Vite, that follows imports and combines modules into files a browser can load efficiently.
- ECMAScript modules — The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
- static analysis — Checking code for problems by reading it, without running it.
Taught in
- Component API Ergonomics: Composition vs Boolean Config Props — Design Systems & Component Engineering
- Component Packaging: Dual ESM/CJS Builds & Package Exports — Design Systems & Component Engineering
- Native Module Systems: ESM Loader Hooks vs CommonJS — Node.js Internals & Backend Services