What is tree shaking?
Tree shaking is a build-time optimisation that removes unused code ("dead code") from the final bundle.
How — bundlers analyse ES Module imports/exports and drop anything never used.
Requirement — relies on static ES Modules; side effects can block removal.
Result: smaller bundles and faster loads — import only what you use, and prefer named exports.
Tree shaking only works with ES Modules (static imports). Named imports ({ debounce } from 'lib') are tree-shakeable.
Namespace imports (import * as lib) are not. sideEffects: false in package.json is required for full tree shaking. The lodash vs lodash-es example shows real impact (70KB+ difference).