tree-shaking
Installation
SKILL.md
Tree-Shaking
Goal: a consumer pays only for what they import. Everything below serves that.
This skill has two parts:
- Always — rules to follow in any library code, without being asked. Violating them silently pins dead code into every consumer bundle.
- On request — architecture tricks. Apply them when the user asks to make an API tree-shakeable, reduce bundle size, or design a new library surface.
In an application
An application is the end of the line: its own build is the last bundler, nothing installs it, and its chunks split by route rather than by a consumer's imports. What keeps dead code out of a chunk holds there too: both annotations, nothing that runs at a module's top level, no enum, statically analyzable ESM built for a modern target, and an honest sideEffects in its own package.json, which its bundler reads for the application's own modules as for any package's. What shapes a package's surface does not:
- An
indexfile may hold its folder's code where the folder is the module, such as a dispatcher over its variants or a list of locales with their loader. It still runs nothing at import. - An
exportsmap and unminified output are a published package's. - Functions over methods and named exports are a library's API: an application's services may be classes, and its pages default exports, as its framework asks.