{"id":19397,"library":"bundle-stats-webpack-plugin","title":"BundleStatsWebpackPlugin","description":"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.","status":"active","version":"4.22.1","language":"javascript","source_language":"en","source_url":"https://github.com/relative-ci/bundle-stats","tags":["javascript","webpack","webpack-plugin","bundle-size","bundle-analyzer","bundle-stats","stats","bundle","size","typescript"],"install":[{"cmd":"npm install bundle-stats-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add bundle-stats-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add bundle-stats-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin works with webpack 4 or 5","package":"webpack","optional":false},{"reason":"Optional peer dependency for Rspack support (0.x or 1.x)","package":"@rspack/core","optional":true}],"imports":[{"note":"The package exports a named export, not default. Use destructured require. ESM import also works: import { BundleStatsWebpackPlugin } from 'bundle-stats-webpack-plugin';","wrong":"import BundleStatsWebpackPlugin from 'bundle-stats-webpack-plugin';","symbol":"BundleStatsWebpackPlugin","correct":"const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin');"},{"note":"ESM import must use named import. The package is ESM-compatible since v4.","wrong":"import BundleStatsWebpackPlugin from 'bundle-stats-webpack-plugin';","symbol":"BundleStatsWebpackPlugin (ESM)","correct":"import { BundleStatsWebpackPlugin } from 'bundle-stats-webpack-plugin';"},{"note":"TypeScript types are included. No need for @types/bundle-stats-webpack-plugin.","wrong":null,"symbol":"BundleStatsWebpackPlugin (TypeScript)","correct":"import { BundleStatsWebpackPlugin } from 'bundle-stats-webpack-plugin';"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new BundleStatsWebpackPlugin({\n      baseline: true, // enables comparison with previous build\n      outDir: './bundle-stats',\n    }),\n  ],\n};","lang":"javascript","description":"Basic webpack configuration using BundleStatsWebpackPlugin with baseline comparison enabled."},"warnings":[{"fix":"Upgrade Node.js to >=14, and webpack to >=4.","message":"Plugin v4 requires Node.js >= 14 and webpack 4 or 5 (webpack 3 not supported).","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use baseline: true option to enable comparison, and check outDir for output.","message":"The output format changed between v3 and v4: baseline comparison now uses a JSON file instead of inline stats.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace `compare: true` with `baseline: true`.","message":"Option `compare` is deprecated in v4; use `baseline` instead.","severity":"deprecated","affected_versions":">=4.0.0 <4.22.0"},{"fix":"Ensure webpack configuration produces stats (e.g., not using lazy: true in devServer).","message":"Plugin will fail silently if webpack stats are not generated (e.g., when using webpack-dev-server with lazy mode).","severity":"gotcha","affected_versions":">=4.0.0"},{"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.","message":"When using Rspack, the plugin requires @rspack/core as a peer dependency and must be imported from the same package.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev bundle-stats-webpack-plugin`","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'bundle-stats-webpack-plugin'"},{"fix":"Use `const { BundleStatsWebpackPlugin } = require('bundle-stats-webpack-plugin');`","cause":"Using default import instead of named import.","error":"TypeError: BundleStatsWebpackPlugin is not a constructor"},{"fix":"Upgrade webpack to version 4 or 5.","cause":"Webpack version is less than 4.","error":"Error: webpack < 4 is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}