{"id":22230,"library":"rollup-plugin-stats","title":"rollup-plugin-stats","description":"A Vite/Rolldown/Rollup plugin that generates a bundle stats JSON file (stats.json) containing detailed information about assets, chunks, and modules. Current stable version is 2.1.1. The plugin is actively maintained, with regular releases (multiple per month). Key differentiators: works across Vite (v5–v8), Rolldown (v1), and Rollup (v3–v4); supports selective asset/module inclusion/exclusion; integrates with RelativeCI and bundle-stats ecosystem for further analysis. Requires Node >=18.","status":"active","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/relative-ci/rollup-plugin-stats","tags":["javascript","vite","rolldown","rollup","vite-plugin","rolldown-plugin","rollup-plugin","bundle-stats","typescript"],"install":[{"cmd":"npm install rollup-plugin-stats","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-stats","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-stats","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v2.0.0, the module provides both ESM and CJS exports; default import works directly. For CommonJS, use require('rollup-plugin-stats') (no .default) as it correctly resolves the module.exports.","wrong":"const pluginStats = require('rollup-plugin-stats').default","symbol":"pluginStats (default)","correct":"import pluginStats from 'rollup-plugin-stats'"},{"note":"TypeScript type exported since v2.1.1","symbol":"PluginStatsOptions","correct":"import { PluginStatsOptions } from 'rollup-plugin-stats'"},{"note":"The Stats interface is a type only; import it with `import type` to avoid runtime issues.","wrong":"import { Stats } from 'rollup-plugin-stats'","symbol":"Stats","correct":"import type { Stats } from 'rollup-plugin-stats'"}],"quickstart":{"code":"import pluginStats from 'rollup-plugin-stats';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  plugins: [\n    pluginStats({\n      fileName: 'stats.json',\n      stats: {\n        source: false,\n        map: false\n      }\n    })\n  ]\n});","lang":"typescript","description":"Shows the minimal Vite config to generate bundle stats JSON. Plugin is added last, output goes to stats.json."},"warnings":[{"fix":"Use `import pluginStats from 'rollup-plugin-stats'` or `const pluginStats = require('rollup-plugin-stats')` (no .default).","message":"v2.0.0 changed default export: previously required require().default, now require() returns the function directly.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Place pluginStats() after all other plugins in the plugins array.","message":"Plugin must be added as the last plugin in the plugins array to capture all build output correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `const pluginStats = require('rollup-plugin-stats')` directly.","message":"v1.x CommonJS usage with require('rollup-plugin-stats').default is deprecated since v2.0.0; will be removed in future major.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Either back up existing stats.json or use a custom `write` option to handle overwriting.","message":"The stats.json file is written by default with `fs.write` which may overwrite existing files without warning.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Only enable `stats.source` if required for analysis; avoid in production CI artifacts.","message":"Setting `stats.source: true` includes full source code in the output, potentially increasing file size significantly and exposing source code.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Upgrade to v2.0.0+ or use dynamic import: `const pluginStats = (await import('rollup-plugin-stats')).default`.","cause":"Using CommonJS require() on an ESM-only version before v2.0.0.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-stats/dist/index.mjs not supported."},{"fix":"Use `const pluginStats = require('rollup-plugin-stats')` (no .default) for CommonJS.","cause":"Using `require('rollup-plugin-stats').default` on v2.0.0+ where the module.exports is already the function.","error":"TypeError: pluginStats is not a function"},{"fix":"Move pluginStats() to the end of the plugins array.","cause":"Plugin not placed as the last plugin in the plugins array.","error":"The stats file is empty or missing assets."},{"fix":"Install with `npm install --save-dev rollup-plugin-stats` and ensure tsconfig includes `node_modules` or has `moduleResolution: 'node'` or 'bundler'.","cause":"Missing dev dependency or TypeScript not configured to resolve types.","error":"Cannot find module 'rollup-plugin-stats' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}