liveBook · Manning

Tree-shaking

Tree-shaking is a build-time optimization that statically identifies and removes unused code from a program's output.

How 2 Manning books explain it

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.

Read how Web Components in Action explains tree-shaking →

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.

Read how The Joy of JavaScript explains tree-shaking →

Related concepts

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.