rollup-plugin-sizes

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

A Rollup plugin that analyzes bundle composition by showing sizes and percentages for each module and its constituent files. Current stable version 1.1.0 (2024) supports Rollup 2, 3, and 4, and is compatible with Vite. It helps identify bloated libraries by printing a hierarchical breakdown of output chunks, optionally with per-file details. Differentiators: lightweight (only 4 dependencies), simple reporter API, and dual ESM/CJS support. Released under MIT license.

error Error: Cannot find module 'rollup-plugin-sizes'
cause Package not installed in node_modules.
fix
Run 'npm install rollup-plugin-sizes --save-dev'.
error TypeError: sizes is not a function
cause Using named import instead of default import.
fix
Use 'import sizes from 'rollup-plugin-sizes'' instead of '{ sizes }'.
error Error: The plugin 'sizes' must be placed after all other plugins.
cause Plugin order incorrect; sizes must be last to get final sizes.
fix
Move sizes() to the end of the plugins array.
error Error: [object Object] is not a function
cause Likely passing options incorrectly (e.g., no parentheses).
fix
Use 'sizes({ details: true })' with parentheses.
gotcha Must be the last plugin in the Rollup plugin list to capture final bundle sizes.
fix Place sizes() after all other plugins in the plugins array.
gotcha Only works with Rollup 2.x, 3.x, or 4.x. Not compatible with Rollup 1.x.
fix Use rollup-plugin-sizes@1.0.0 or later with Rollup >=2.
gotcha If no bundle is generated (e.g., due to errors), the plugin will not output any size information.
fix Ensure the build completes successfully before expecting output.
gotcha The 'details' option may produce very verbose output for large bundles.
fix Set details: false (default) to see only top-level module sizes.
npm install rollup-plugin-sizes
yarn add rollup-plugin-sizes
pnpm add rollup-plugin-sizes

Shows how to add the plugin to a Rollup config, enabling per-file breakdown.

import sizes from 'rollup-plugin-sizes';

export default {
  input: 'src/main.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    sizes({
      details: true
    })
  ]
};