Tree-shaking
Tree-shaking is a build-time optimization that statically identifies and removes unused code from a program's output.
Web Components in Action
Tree shaking is static analysis that removes imported code and other module parts that are not used from a bundle.
- How it is used
- Reduces JavaScript bundle size during the build process by excluding unused imported modules.
- How deep it goes
- Defines import tracking and omission, then stops short of explaining the analysis algorithm or configuration details.
- Examples
- Uses an unused module and a banking application separating transaction and account-information bundles.
- What you can do after
- Apply it via Rollup or Webpack to create smaller bundles containing only needed module code.
The Joy of JavaScript
A bundler optimization that removes unused exports, modules, or code paths from a program during build time.
- How it is used
- Reduces bundled application payloads by eliminating unused modules and code during build time.
- How deep it goes
- Explains dependency analysis, ESM constraints, module design, and pure-call removal, but defers specific build-tool usage.
- Examples
- Uses unused exports, bundled dependency trees, and pure validation calls as removal examples.
- What you can do after
- Evaluate module designs and understand how ESM enables bundlers to remove unreachable code.
Related concepts
- CommonJScontrasts with · CommonJS is a JavaScript module-system specification that defines how modules export and load values, traditionally using synchronous require calls and module.exports assignments.
- Viteused by · Vite is a frontend development tool that provides a development server and production build pipeline for modern web applications.
- package.jsonconfigured by · package.json is the standard JSON manifest for an npm or Node.js package, declaring metadata, dependencies, scripts, entry points, and related configuration.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

