Vite Bundle Analyzer

raw JSON →
1.3.7 verified Sat Apr 25 auth: no javascript

A bundle analyzer for Vite, Rollup, and Rolldown that visualizes bundle size with an interactive treemap. Current stable version is 1.3.7. Released actively with multiple updates per month. Differentiators: supports multiple bundlers (Vite, Rollup, Rolldown), multiple output modes (server, static, json, custom), customizable size metrics (stat, gzip, brotli), and TypeScript types included.

error Cannot find module 'vite-bundle-analyzer'
cause Installed as devDependency but not installed globally or in node_modules.
fix
Run 'npm install vite-bundle-analyzer --save-dev' in your project.
error SyntaxError: Cannot use import statement outside a module
cause Using CommonJS require or running Node in non-ESM mode.
fix
Use import syntax or set type:'module' in package.json.
error Error: Plugin is only applicable during the build phase
cause Used analyzer plugin in dev server or without build.
fix
Remove plugin from dev server config or run 'npx vite build'.
breaking Static mode now opens HTML reports via file protocol instead of starting a server (since v1.2.3).
fix If you rely on a server, set analyzerPort option.
deprecated Rolldown plugin is experimental (unstableRolldownAdapter).
fix Monitor releases for stable Rolldown support.
gotcha Vite enables minification by default; parsed size may appear larger than actual size.
fix Use 'gzip' or 'brotli' as defaultSizes for more realistic sizes.
gotcha Plugin only works during build phase, not dev server.
fix Ensure you run npx vite build to generate analysis.
npm install vite-bundle-analyzer
yarn add vite-bundle-analyzer
pnpm add vite-bundle-analyzer

Shows how to configure and run the analyzer in static mode with gzip size report.

// vite.config.ts
import { defineConfig } from 'vite';
import { analyzer } from 'vite-bundle-analyzer';

export default defineConfig({
  plugins: [
    analyzer({
      analyzerMode: 'static',
      fileName: 'report',
      reportTitle: 'My App Bundle',
      defaultSizes: 'gzip',
      openAnalyzer: true,
    })
  ]
});
// Run: npx vite build --config vite.config.ts