rollup-plugin-filesize-check

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

A tiny Rollup plugin that validates that the output bundle size is within an expected range. Currently at version 1.2.0, it offers a simple API: provide an expected size (in kB) and a tolerance (warn) in kB. The plugin warns or errors if the actual size deviates beyond the tolerance. Unlike more feature-rich alternatives like rollup-plugin-filesize or rollup-plugin-sizes, this package focuses purely on size checking with minimal configuration and no visual reporting. It has stable, low release cadence, and is intended for developers who want CI-style size enforcement in their Rollup builds.

error Error: Cannot find module 'rollup-plugin-filesize-check'
cause Package not installed or ESM/CJS mismatch. The package is ESM-only and must be imported with 'import', not 'require'.
fix
Run 'npm install rollup-plugin-filesize-check --save-dev'. Use 'import sizeCheck from 'rollup-plugin-filesize-check'' in your Rollup config. If using CommonJS, consider dynamic import: 'const sizeCheck = (await import('rollup-plugin-filesize-check')).default'.
error TypeError: sizeCheck is not a function
cause CommonJS require() of an ESM module, or using wrong import syntax (e.g., named import instead of default).
fix
Ensure you use the default import: 'import sizeCheck from 'rollup-plugin-filesize-check''.
error Plugin failed: rollup-plugin-filesize-check: expect option is required
cause Missing 'expect' option in plugin invocation, or it's undefined/null.
fix
Provide the 'expect' option with a number in kB: 'sizeCheck({ expect: 100 })'.
gotcha The 'warn' option has a misleading name; it sets a tolerance threshold, not a warning level. If the actual size deviates by more than this value, the plugin prints a warning (red text) but does not fail the build.
fix Set 'warn' to the maximum acceptable difference in kB. To fail the build, you need to handle this outside the plugin (e.g., custom check or CI).
npm install rollup-plugin-filesize-check
yarn add rollup-plugin-filesize-check
pnpm add rollup-plugin-filesize-check

Rollup config using sizeCheck plugin to validate bundle size within +/-5 kB of 95 kB.

// install: npm i rollup-plugin-filesize-check --save-dev

import sizeCheck from 'rollup-plugin-filesize-check';

export default {
  input: 'src/index.js',
  output: [{ file: 'builds/out.js', format: 'umd' }],
  plugins: [
    sizeCheck({
      expect: 95, // expected size in kB
      warn: 5     // acceptable deviation in kB
    })
  ]
};