EasyBundle Optimization📖 Theory Question

How do you analyze and diagnose large bundle sizes?

💡

Hint

webpack-bundle-analyzer, Vite's rollup-plugin-visualizer, source-map-explorer — find what is large and why

Full Answer

Tools:

  • webpack-bundle-analyzer — generates an interactive treemap of all modules and their sizes. Run with ANALYZE=true next build.
  • rollup-plugin-visualizer / vite-bundle-visualizer — equivalent for Vite/Rollup.
  • source-map-explorer — analyzes the production source map to show the real size contribution of each module.
  • Bundlephobia — check the size of npm packages before installing them.

Common culprits found during analysis:

  • Moment.js locale files — ~70 kB of locale data bundled even if you only use English. Fix: use date-fns or configure IgnorePlugin to exclude locales.
  • Full lodashimport _ from 'lodash' bundles everything. Fix: import debounce from 'lodash/debounce' or use lodash-es.
  • Barrel file importsimport { X } from '@ui' may pull in the entire library. Fix: deep imports or sideEffects: false.
  • Duplicate packages — two versions of the same package in node_modules due to peer dep conflicts.

More Bundle Optimization Questions

EasyWhat is tree shaking and what conditions must be met for it to work?EasyWhat is code splitting and how does dynamic import() enable it?EasyWhat is vendor chunk splitting and why is it important for caching?MediumWhat is the module/nomodule pattern for differential serving?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint