rollup-plugin-bundle-stats
raw JSON → 4.22.1 verified Mon Apr 27 auth: no javascript
Analyze Rollup, Vite, and Rolldown bundle stats (size, assets, modules, packages) with support for side-by-side comparison between builds. Current stable version is 4.22.1, released under the MIT license. It outputs HTML reports and integrates with RelativeCI for continuous monitoring. Key differentiators include duplicate package detection, cache invalidation metrics, and multi-build comparison. Ships TypeScript types. Requires Node >= 16. Peer dependencies: Rollup ^3 || ^4, Vite ^5 || ^6 || ^7 || ^8, Rolldown ^1.0.0-beta.0. Actively maintained on GitHub with weekly or monthly releases.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/rollup-plugin-bundle-stats from ... not supported. Instead change the require of ... to a dynamic import() which is available in all CommonJS modules. ↓
cause Using require() on v4 ESM-only package in a CommonJS context
fix
Use dynamic import:
const { bundleStats } = await import('rollup-plugin-bundle-stats') or switch to ESM error TypeError: bundleStats is not a function ↓
cause Incorrect import: using default import instead of named import
fix
Use named import:
import { bundleStats } from 'rollup-plugin-bundle-stats' error Error: Cannot find module 'rollup-plugin-bundle-stats' ↓
cause Missing installation or incorrect module resolution
fix
Install the package:
npm install --dev rollup-plugin-bundle-stats Warnings
breaking v4 drops CommonJS support and requires ESM imports; require() will throw ↓
fix Use ES module syntax: `import { bundleStats } from 'rollup-plugin-bundle-stats'`
breaking Peer dependency range changed in v4; incompatible with Rollup <3 or Vite <5 ↓
fix Ensure Rollup ^3 || ^4, Vite ^5 || ^6 || ^7 || ^8
gotcha Option `compare` requires a baseline file from a previous build; otherwise report will be empty ↓
fix Run with `baseline: true` first to generate baseline JSON, then subsequent runs with `compare: true`
deprecated Option `stats` was deprecated in v3 and removed in v4; use `bundleStats()` directly ↓
fix Remove `stats` option; pass options directly to `bundleStats()`
Install
npm install rollup-plugin-bundle-stats yarn add rollup-plugin-bundle-stats pnpm add rollup-plugin-bundle-stats Imports
- bundleStats wrong
const bundleStats = require('rollup-plugin-bundle-stats')correctimport { bundleStats } from 'rollup-plugin-bundle-stats' - BundleStatsOptions wrong
import { BundleStatsOptions } from 'rollup-plugin-bundle-stats'correctimport type { BundleStatsOptions } from 'rollup-plugin-bundle-stats' - bundleStats wrong
const bundleStats = require('rollup-plugin-bundle-stats')correctconst { bundleStats } = await import('rollup-plugin-bundle-stats')
Quickstart
// vite.config.js
import { defineConfig } from 'vite';
import { bundleStats } from 'rollup-plugin-bundle-stats';
export default defineConfig({
plugins: [
bundleStats({
compare: true,
baseline: true,
html: true,
json: false,
outDir: 'bundle-stats',
silent: false
})
]
});