Verifying Tree Shaking Results
You'll learn how to confirm that your bundler actually removed unused code from production builds using bundle analysis tools.
Why Verification Matters
Tree shaking promises smaller bundles by eliminating dead code, but how do you know it worked? Just because you configured it doesn't mean unused exports vanished. Verification is like checking your grocery receipt—you want proof you only paid for what you're taking home, not the entire store inventory.
Core Verification Techniques
Bundle Analysis Tools let you inspect the final output. Most bundlers offer built-in or plugin-based visualizers:
- Webpack Bundle Analyzer creates an interactive treemap showing which modules and code ended up in your bundle
- Rollup Plugin Visualizer generates similar charts for Rollup builds
- Vite's
rollup-plugin-visualizerworks during production builds
These tools reveal file sizes, which imports contributed what code, and where bloat hides.
Manual Inspection involves searching your production bundle file for specific function names or exports you expected to disappear. If you see unusedHelperFunction in the minified output, tree shaking failed for that code.
Size Comparison means tracking bundle size over time. Significant jumps might indicate tree shaking broke (perhaps a side effect was introduced).
What You're Looking For
- Unused exports from libraries should be absent
- Code guarded by
if (false)or unreachable branches should vanish - Utility functions you didn't import shouldn't appear
If something is present unexpectedly, revisit your sideEffects configuration, check for dynamic imports, or look for hidden references.
Key Takeaway: Bundle analysis tools transform tree shaking from wishful thinking into measurable reality—use them to confirm your production build contains only the code you actually use.