Tree-Shaking Analyzer detects dead exports in ESM or CJS modules and estimates the KB impact per dead export. It generates a ready-to-paste package.json sideEffects field with per-file reasoning, outputs an optimized barrel file as a drop-in replacement, and renders a Mermaid dependency graph with dead paths highlighted. Five outputs in one call.
Tree-Shaking Analyzer
Find dead exports, estimate bundle savings, generate sideEffects field
How to use
- Paste module source — Drop in the entry file or barrel index of a module — what you ship in package.json main or exports.
- Select module format — Choose esm for ES modules with import/export. Choose cjs for require/module.exports.
- Specify entry exports (optional) — List the exports actually consumed by your application. Everything else is marked as dead candidate.
- Enable optional outputs — Toggle estimateBundleSize, generateSideEffects, generateBarrel, and outputGraph for the outputs you need.
- Analyze and act — Review the bundleSizeReport, paste the sideEffectsField into package.json, and replace your barrel with the generated one.
MCP / API
Call tree_shaking_analyzer directly from any MCP-compatible agent:
// MCP TypeScript SDK
const result = await client.callTool({
name: "tree_shaking_analyzer",
arguments: {
"code": "...",
"format": "esm"
}
});
// curl
curl -X POST https://obfus.link/mcp \
-H "Authorization: Bearer <SPT>" \
-H "Content-Type: application/json" \
-d '{"method":"tools/call","params":{"name":"tree_shaking_analyzer","arguments":{"code":"...","format":"esm"}}}'Related tools
FAQ
Why does ESM tree-shake better than CJS?
ESM imports are static (declared at module scope, resolved at parse time), so bundlers can safely eliminate unused exports. CJS require() is dynamic and may have side effects, so bundlers must conservatively include the whole module. The analyzer reports both formats but CJS rarely benefits from tree-shaking in real bundlers.
What does Entry Simulation mean?
When you provide entryExports — the exports your app actually consumes — the analyzer marks every other export as a dead-code candidate. This turns a static export report into an actionable removal list specific to your usage, not just "what looks unused."
How accurate is the bundle size estimate?
The estimator computes the gzipped byte size each dead export contributes to a typical Webpack or Vite bundle, accounting for shared imports between exports. It is a conservative estimate (real bundlers may eliminate slightly more), but the relative ranking of exports by KB impact is reliable for prioritization.
What does the package.json sideEffects field actually do?
It tells bundlers which files in a package have import-time side effects and must be retained even if no exports are used. Setting sideEffects: false unlocks aggressive tree-shaking. Setting it to a glob array preserves specific files. Getting this wrong silently breaks either tree-shaking or runtime behavior — the generator gets it right.
Can I use this tool via the MCP API?
Yes. The tool is registered on the obfus.link MCP server at https://obfus.link/mcp. Call it from any MCP-compatible agent with a Shared Payment Token. The MCP tool name matches the snake_case slug shown in the integration snippet.