Interactive bundle analysis using rollup-plugin-visualizer to visualize which modules take up the most space.
Installed package: rollup-plugin-visualizer
Run any of these commands to build and analyze:
# Production build with analysis
pnpm analyze
# Development build with analysis
pnpm analyze:dev
# Production build with Sentry + analysis
pnpm analyze:sentryThis will:
- Build your application
- Generate
build/stats.htmlwith an interactive visualization - Automatically open it in your browser
The visualization shows:
- Module sizes - Both original and gzipped/brotli sizes
- Bundle composition - Which packages/modules contribute most to bundle size
- Interactive treemap - Click to drill down into dependencies
- Size metrics - Stat size, parsed size, gzipped size, and brotli size
- Large dependencies - Packages taking up significant space
- Duplicate modules - Same module bundled multiple times
- Unused code - Large imports when only small parts are needed
- Code splitting opportunities - Large chunks that could be split
- Replace large libraries with smaller alternatives
- Use dynamic imports for code splitting
- Enable tree-shaking by using ES modules
- Check for accidentally imported test files or dev dependencies
Set the ANALYZE environment variable:
# macOS/Linux
ANALYZE=true pnpm build
# Windows (PowerShell)
$env:ANALYZE="true"; pnpm build
# Windows (CMD)
set ANALYZE=true && pnpm buildThe analyzer is configured in vite.config.mjs and vite.sentry.config.mjs:
visualizer({
open: true, // Auto-open in browser
filename: 'build/stats.html',
gzipSize: true, // Show gzipped sizes
brotliSize: true, // Show brotli sizes
});