rollup-plugin-gzip
raw JSON → 4.2.0 verified Mon Apr 27 auth: no javascript
A Rollup/Vite plugin that creates compressed .gz and .br artifacts from bundle output files. Current version is 4.2.0, with major releases every 1-2 years. Supports both gzip (via Node's zlib) and custom compression algorithms (Brotli, Zopfli). Key differentiators: built-in Brotli support via custom compression, file size threshold filtering, additional file compression, and compatibility with Vite and Rollup (>=2.0.0). TypeScript types included.
Common errors
error Error: gzipPlugin is not a function ↓
cause CommonJS require returns an ES module with default as object property.
fix
Use const gzipPlugin = require('rollup-plugin-gzip').default; or switch to ESM import.
error Error: Cannot find module 'rollup-plugin-gzip' ↓
cause Package not installed.
fix
Run npm install --save-dev rollup-plugin-gzip
error Error: [plugin:gzip] Failed to compress with brotli: 'brotliCompress' is not a function ↓
cause Using Node <11.7.0 with built-in brotli.
fix
Upgrade Node to >=11.7.0 or install 'brotli' package and use it as customCompression.
error Error: Rollup version 1.x is not supported, please upgrade to 2.x or higher ↓
cause Using outdated Rollup version.
fix
Upgrade Rollup to >=2.0.0 or use v2.x of this plugin.
Warnings
breaking v4.0.0 switched to type: "module". Import syntax changed; CommonJS users must use dynamic import or upgrade. ↓
fix Use ESM imports: import gzipPlugin from 'rollup-plugin-gzip'; or const gzipPlugin = (await import('rollup-plugin-gzip')).default;
breaking v3.0.0 dropped support for Rollup versions < 2.0.0. ↓
fix Upgrade Rollup to >=2.0.0, or use v2.x of this plugin.
gotcha If using Brotli compression with Node < 11.7.0, you need the external 'brotli' package. ↓
fix Use Node >=11.7.0 or install 'brotli' from npm and use it as customCompression.
gotcha The 'gzipOptions' object is passed directly to Node's zlib. Options like 'level' and 'memLevel' are supported, but incorrect values may cause errors. ↓
fix Refer to https://nodejs.org/api/zlib.html#zlib_class_options for valid options.
breaking v2.5.1 fails build when detecting incompatible Vite bundle to force upgrade to v3.x. ↓
fix Upgrade to v3.x or above.
deprecated The 'additionalFilesDelay' option is deprecated for Rollup >=2.0.0 (defaults to 0). ↓
fix Remove the option or set to 0.
Install
npm install rollup-plugin-gzip yarn add rollup-plugin-gzip pnpm add rollup-plugin-gzip Imports
- gzipPlugin wrong
const gzipPlugin = require('rollup-plugin-gzip')correctimport gzipPlugin from 'rollup-plugin-gzip'
Quickstart
// rollup.config.js
import gzipPlugin from 'rollup-plugin-gzip';
import { brotliCompress } from 'zlib';
import { promisify } from 'util';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'esm'
},
plugins: [
gzipPlugin() // defaults: .gz, minSize optional
]
};