BundleStatsWebpackPlugin
raw JSON → 4.22.1 verified Sat Apr 25 auth: no javascript
In-depth bundle analyzer for webpack (and Rspack) that generates detailed HTML reports on bundle size, assets, modules, and packages, with side-by-side comparison support. Current stable version v4.22.1, actively maintained with frequent releases. Supports webpack 4 & 5, Rspack 0.x & 1.x, and also has plugins for Vite, Rollup, and Rolldown. Key differentiators: it provides not only size analysis but also duplicate package detection, cache invalidation metrics, and historical comparison via RelativeCI. Ships TypeScript types.
Common errors
error Cannot find module 'bundle-stats-webpack-plugin' ↓
cause Package not installed or not in node_modules.
fix
Run
npm install --save-dev bundle-stats-webpack-plugin error TypeError: BundleStatsWebpackPlugin is not a constructor ↓
cause Using default import instead of named import.
fix
Use
const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin'); error Error: webpack < 4 is not supported ↓
cause Webpack version is less than 4.
fix
Upgrade webpack to version 4 or 5.
Warnings
breaking Plugin v4 requires Node.js >= 14 and webpack 4 or 5 (webpack 3 not supported). ↓
fix Upgrade Node.js to >=14, and webpack to >=4.
breaking The output format changed between v3 and v4: baseline comparison now uses a JSON file instead of inline stats. ↓
fix Use baseline: true option to enable comparison, and check outDir for output.
deprecated Option `compare` is deprecated in v4; use `baseline` instead. ↓
fix Replace `compare: true` with `baseline: true`.
gotcha Plugin will fail silently if webpack stats are not generated (e.g., when using webpack-dev-server with lazy mode). ↓
fix Ensure webpack configuration produces stats (e.g., not using lazy: true in devServer).
gotcha When using Rspack, the plugin requires @rspack/core as a peer dependency and must be imported from the same package. ↓
fix Install @rspack/core and use the Rspack import: const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin'); still works, but ensure webpack is not installed as it might conflict.
Install
npm install bundle-stats-webpack-plugin yarn add bundle-stats-webpack-plugin pnpm add bundle-stats-webpack-plugin Imports
- BundleStatsWebpackPlugin wrong
import BundleStatsWebpackPlugin from 'bundle-stats-webpack-plugin';correctconst { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin'); - BundleStatsWebpackPlugin (ESM) wrong
import BundleStatsWebpackPlugin from 'bundle-stats-webpack-plugin';correctimport { BundleStatsWebpackPlugin } from 'bundle-stats-webpack-plugin'; - BundleStatsWebpackPlugin (TypeScript)
import { BundleStatsWebpackPlugin } from 'bundle-stats-webpack-plugin';
Quickstart
// webpack.config.js
const path = require('path');
const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
new BundleStatsWebpackPlugin({
baseline: true, // enables comparison with previous build
outDir: './bundle-stats',
}),
],
};