tree-shaking

Eliminates dead exports and unreachable module code from JavaScript bundles during builds.

Updated Mar 27, 2026
One-click install
npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill tree-shaking-quanngynx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tree-shaking
Source: https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI/tree/main/servexa-warranty-ai/.agents/skills/tree-shaking
Command: npx skills add https://github.com/quanngynx/GDGO-2026.Servexa-Warranty-AI --skill tree-shaking-quanngynx

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Tree shaking eliminates unused (dead) code from JavaScript bundles so your app downloads faster and loads with less overhead.

Core Features & Use Cases

  • Dead-code elimination: Removes exports and module parts that are never reached from your entry graph.
  • ES module compatibility: Ensures bundlers can statically analyze import/export structure.
  • Side-effect awareness: Prevents incorrect removal of modules or statements that must run (e.g., polyfills, global styles).

Quick Start

Use ES module import/export syntax with named imports, and mark only truly side-effect-free packages in package.json so your bundler can safely drop unused code.

Frequently Asked Questions about tree-shaking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does tree shaking remove dead code from JavaScript bundles?

Tree shaking removes dead code from JavaScript bundles by statically analyzing ES module import and export structure to drop unused exports and unreachable module code during builds. This eliminates unused exported functions so applications download and parse faster.

Do I need ES modules for tree shaking to work?

Yes, tree shaking requires ES2015 module syntax with named imports and exports. Bundlers rely on the static structure of ES modules to analyze dependencies and safely remove dead code, which is not possible with dynamic CommonJS require statements.

How do I keep polyfills and global styles from being removed by tree shaking?

To prevent tree shaking from incorrectly removing polyfills and global styles, configure correct package.json sideEffects settings. This marks modules with side effects so the bundler retains them while still dropping truly side-effect-free unused code.

Can I use tree shaking with both Webpack and Rollup?

Yes, tree shaking works with both Webpack and Rollup for JavaScript bundling. Both bundlers apply dead code elimination by analyzing ES module imports, provided you use ES2015 syntax and configure package.json sideEffects correctly.

What is the best way to shrink a large JavaScript bundle?

The best way to shrink a large JavaScript bundle is using tree shaking to eliminate dead exports and unreachable module code. You must apply ES module syntax with named imports and accurate package.json sideEffects configuration for safe dead code elimination.