rollup-plugin-bundle-analyzer

raw JSON →
1.6.6 verified Mon Apr 27 auth: no javascript

A Rollup plugin that visualizes the size of output files as an interactive zoomable treemap. Version 1.6.6 supports Rollup ^1.20.0 || ^2.0.0 || ^3.0.0, requires Node >=14.0.0, and ships TypeScript types. It provides multiple analyzer modes (server, static, json) and can display input, rendered (minified), and gzipped sizes. Unlike webpack-bundle-analyzer, this plugin is specifically for Rollup/Vite projects and parses minified bundles to show real module sizes. It supports excluding assets via patterns.

error Error: Cannot find module 'rollup-plugin-bundle-analyzer'
cause Package not installed or not in node_modules
fix
Run 'npm install --save-dev rollup-plugin-bundle-analyzer'
error TypeError: bundleAnalyzer is not a function
cause Imported incorrectly (named import instead of default import).
fix
Use: import bundleAnalyzer from 'rollup-plugin-bundle-analyzer'
error Error: The current Rollup version (4.x.x) is not supported by rollup-plugin-bundle-analyzer
cause Plugin only supports Rollup versions 1-3.
fix
Downgrade Rollup to version 3.x or use an alternative plugin.
breaking Plugin does not work with Rollup 4.x. Only supports Rollup ^1.20.0 || ^2.0.0 || ^3.0.0.
fix Use the official rollup-plugin-analyzer or wait for an update. Alternatively, pin rollup to version 3.x.
gotcha Options object properties are case-sensitive: 'analyzerMode', not 'mode'. 'host', not 'hostname'.
fix Check your options object keys against the documentation.
gotcha The 'reportFilename' in 'static' mode is relative to the output directory, not the project root.
fix Use an absolute path or ensure the relative path is correct.
deprecated Some options like 'startAutomatically' and 'openBrowser' are removed in recent versions.
fix Remove these options. They are no longer supported.
npm install rollup-plugin-bundle-analyzer
yarn add rollup-plugin-bundle-analyzer
pnpm add rollup-plugin-bundle-analyzer

Configures rollup to generate a static HTML report and a stats JSON file, excluding source maps.

// rollup.config.js
import bundleAnalyzer from 'rollup-plugin-bundle-analyzer';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    bundleAnalyzer({
      analyzerMode: 'static',
      reportFilename: 'bundle-report.html',
      generateStatsFile: true,
      statsFilename: 'stats.json',
      excludeAssets: '*.map'
    })
  ]
};