rollup-plugin-zip
raw JSON → 1.0.3 verified Mon Apr 27 auth: no javascript
Rollup plugin that creates a ZIP archive of emitted files during the build process. Version 1.0.3 is the latest stable version, with occasional minor updates. It integrates directly with Rollup's output pipeline, archiving only the files emitted by the bundle, not additional assets (those require separate handling via plugins like rollup-plugin-copy2). This plugin is inspired by zip-webpack-plugin and supports custom output filenames and directories.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/node_modules/rollup-plugin-zip/src/index.js not supported. ↓
cause Package is pure ESM; require() is used instead of import.
fix
Use
import zip from 'rollup-plugin-zip' in an ES module context. error TypeError: zip is not a function ↓
cause Named import `{ zip }` used instead of default import.
fix
Use
import zip from 'rollup-plugin-zip' without curly braces. error The plugin 'rollup-plugin-zip' is not exporting a valid rollup plugin. ↓
cause Plugin factory function returned undefined or incorrect object.
fix
Ensure you call
zip() (with parentheses) in your plugins array, e.g., plugins: [zip()]. Warnings
gotcha Plugin does not archive manually placed assets outside Rollup's emitted files. ↓
fix Use rollup-plugin-copy2 or similar to copy additional assets before zipping.
gotcha If both `file` and `dir` options are provided, `dir` is ignored. ↓
fix Use only `file` or only `dir` to avoid confusion; set path relative to output dir or package root accordingly.
breaking Package is pure ESM and cannot be imported via require(). ↓
fix Switch to ES module syntax in your project or use dynamic import.
Install
npm install rollup-plugin-zip yarn add rollup-plugin-zip pnpm add rollup-plugin-zip Imports
- default wrong
const zip = require('rollup-plugin-zip')correctimport zip from 'rollup-plugin-zip' - zip wrong
import { zip } from 'rollup-plugin-zip'correctimport zip from 'rollup-plugin-zip' - ZipOptions
import type { ZipOptions } from 'rollup-plugin-zip'
Quickstart
// rollup.config.js (ESM)
import zip from 'rollup-plugin-zip';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'es',
},
plugins: [
zip({
file: 'bundle.zip',
dir: 'archives',
}),
],
};