rollup-plugin-brotli

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

Rollup plugin that creates Brotli-compressed .br artifacts for your bundle. Current stable version is 3.1.0, maintained with irregular releases. Uses Node.js built-in zlib.createBrotliCompress (requires Node >=11.7.0). Differentiates from alternatives like rollup-plugin-gzip by focusing solely on Brotli and leveraging native Node APIs. Offers configurable options: file extension filtering via RegExp test, brotli compression params (mode, quality), additional files list, and minSize threshold to skip small files.

error Error: Node >= 11.7.0 is required for the built-in brotli support
cause Node version < 11.7.0 does not have native Brotli support; plugin since v2.0.0 uses native zlib.
fix
Upgrade Node to version >=11.7.0.
error The 'test' option has been removed. Use the 'test' option to filter files.
cause Misreading documentation; actually test option was added in v3.1.0 but some users may use older version.
fix
Update plugin to v3.1.0 or later, or use the include/exclude pattern? Actually no include/exclude, so use test.
error Cannot read property 'fileName' of undefined
cause Occurs when using output.file and the plugin expects output.dir.
fix
Use output.dir instead of output.file, or adapt plugin configuration.
error TypeError: brotli is not a function
cause Using named import incorrectly: import { brotli } from 'rollup-plugin-brotli' works, but if using default import with wrong syntax.
fix
Ensure import is correct: import brotli from 'rollup-plugin-brotli' or import { brotli } from 'rollup-plugin-brotli'.
breaking v2.0.0 dropped Brotli implementation from node-brotli package in favor of native Node.js zlib.createBrotliCompress.
fix Update Node to >=11.7.0 and remove node-brotli from dependencies.
deprecated v2.0.0 removed the `test` option? (Actually added later in v3.1.0, so not deprecated.)
gotcha If output.file is used (single bundle) and no output.dir, the plugin may create .br file next to the output file; but if output.dir is used, it compresses all output chunks matching the test pattern.
fix Use output.dir for multi-chunk outputs; ensure file extension matches test regex.
gotcha Default quality is 11 (maximum compression), which is slow. For faster builds, set quality lower (e.g., 4 or 7).
fix Set options.params[zlib.constants.BROTLI_PARAM_QUALITY] to a lower value.
breaking v2.0.0 changed from using the `node-brotli` npm package to Node's built-in zlib. This is a breaking change because it requires Node >=11.7.0 and the option names changed.
fix Ensure Node >=11.7.0, use zlib constants instead of node-brotli options.
npm install rollup-plugin-brotli
yarn add rollup-plugin-brotli
pnpm add rollup-plugin-brotli

Shows typical rollup configuration using rollup-plugin-brotli with all options.

import brotli from 'rollup-plugin-brotli';
import zlib from 'zlib';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [
    brotli({
      test: /\.(js|css|html|txt|xml|json|svg|ico|ttf|otf|eot)$/,
      options: {
        params: {
          [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_GENERIC,
          [zlib.constants.BROTLI_PARAM_QUALITY]: 7
        }
      },
      additional: ['dist/bundle.css'],
      minSize: 1000
    })
  ]
};