rollup-plugin-zipdir
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that zips the entire output directory after build using fflate. Current stable version is 1.0.1, released in 2023 with low release cadence. Unlike rollup-plugin-zip which zips in-memory assets, this plugin reads files directly from the output directory on disk and operates late in Rollup's output generation phase, ensuring all files are written. Written in TypeScript with bundled types. No known breaking changes.
Common errors
error Error: Cannot read properties of undefined (reading 'dir') ↓
cause Plugin expects output.dir to be defined, but config uses output.file or output is missing.
fix
Set output.dir in Rollup config (e.g., output: { dir: 'build' }).
error TypeError: zipDir is not a function ↓
cause Using named import instead of default import.
fix
Use default import: import zipDir from 'rollup-plugin-zipdir';
Warnings
gotcha Plugin must be the last plugin in the Rollup plugins array because it runs in the generateBundle hook. If placed earlier, files may not exist yet. ↓
fix Ensure zipDir is the last entry in the plugins array.
gotcha The outputDir option defaults to 'zip', not the current directory. If not specified, zip file will be placed in a folder named 'zip' relative to the output directory. ↓
fix Explicitly set outputDir option to desired path.
deprecated Plugin is ESM-only; requires Node.js 14+ or bundler with ESM support. ↓
fix Use import syntax and ensure project uses ESM.
Install
npm install rollup-plugin-zipdir yarn add rollup-plugin-zipdir pnpm add rollup-plugin-zipdir Imports
- zipDir wrong
const zipDir = require('rollup-plugin-zipdir');correctimport zipDir from 'rollup-plugin-zipdir'; - ZipDirOptions
import type { ZipDirOptions } from 'rollup-plugin-zipdir'; - default export (named function) wrong
import { zipDir } from 'rollup-plugin-zipdir';correctimport zipDir from 'rollup-plugin-zipdir'; zipDir({ outputDir: 'dist' });
Quickstart
// rollup.config.js (ESM)
import zipDir from 'rollup-plugin-zipdir';
export default {
input: 'src/index.js',
output: {
dir: 'build',
format: 'esm',
},
plugins: [
// Must be placed last in plugins array
zipDir({
outputDir: 'dist', // default: 'zip'
filter: (file) => !file.endsWith('.map'), // optional: exclude sourcemaps
}),
],
};