Andrew's Digital Garden

Tree shaking

Tree shaking is a form of [[dead code elimination]]. It removes unreachable code ('dead code') from a bundle.

This reduces the size of the final bundle, while requiring minimal work from the developer.

Note that statements like import * as x from dependency removes a bundler's ability to tree shake, as it imports everything from the dependency, and can't tell what is unused.

Only ESM packages can be tree shaken.

The sideEffects property in package.json can have a large effect on the performance of tree shaking.

[[buildtooling]] [[dependencies]] [[deployment]] [[npm]] [[performance]] [[web]] [[webpack]]

Tree shaking