
tree-shaking
Teaches tree shaking for dead code elimination in JavaScript bundles
by patternsdevFree
Description
Explains tree shaking, the build step that removes unused code from a JavaScript bundle before it ships. Code that is imported but never used can be dropped from the final bundle, which keeps the download smaller and the page faster to load. The skill covers the main rules. Use ES2015 import and export syntax, because only ES modules can be tree-shaken. Import named exports instead of whole modules, so the bundler can see what is unused. Mark packages as side-effect-free in package.json when that is accurate. Be aware that modules with side effects cannot be safely removed, even when their exports look unused. It also explains the concepts behind dead code elimination. Use it when a bundle includes code from imported modules that the app never calls, or when you want to reduce bundle size and improve load performance. It is a short guide for the build side of a web app, and it does not replace measuring what actually ships.…
Highlights
- Use ES module import and export syntax
- Import named exports rather than whole modules
- Mark side-effect-free packages in package.json
- Why modules with side effects are kept
Ratings & Reviews
No ratings yet
Be the first to rate tree-shaking.
People also visit
tree-shaking FAQ
What is tree shaking?
Removing code that is imported but never used, so the JavaScript bundle that ships is smaller.
Why does import style matter?
Only ES modules can be tree-shaken, and named imports let the bundler see which exports are unused.
Does it remove every unused module?
No. Modules with side effects cannot be safely removed, even when their exports look unused.
How do I install it?
Run: npx skills add https://github.com/patternsdev/skills --skill tree-shaking
What do the security audits show?
Gen Agent Trust Hub: Pass. Socket: Pass. Snyk: Pass.
What are the best tree-shaking alternatives?
Popular alternatives to tree-shaking include audit-and-reduce-dependencies, knip and javascript-pro. See all tree-shaking alternatives



















