{"id":23013,"library":"zip-webpack-plugin","title":"Zip Webpack Plugin","description":"Webpack plugin that compresses all emitted assets into a single zip file. Current stable version is 4.0.3, supporting Webpack 4 and 5 (and Rspack experimentally). It uses yazl for zip creation and offers options for path prefix, filename, extension, include/exclude filters, and compression control. Compared to alternatives like `webpack-plugin-zip`, it is lightweight, well-maintained, and straightforward. Release cadence is sporadic; major versions introduce breaking changes for Webpack major upgrades.","status":"active","version":"4.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/erikdesjardins/zip-webpack-plugin","tags":["javascript","webpack"],"install":[{"cmd":"npm install zip-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add zip-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add zip-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin runs within Webpack compilation lifecycle.","package":"webpack","optional":false},{"reason":"Peer dependency; used for asset source handling (RawSource in Webpack 5).","package":"webpack-sources","optional":false}],"imports":[{"note":"Package is CommonJS-only; ESM import may fail in strict ESM environments.","wrong":"import ZipPlugin from 'zip-webpack-plugin';","symbol":"ZipPlugin","correct":"const ZipPlugin = require('zip-webpack-plugin');"},{"note":"ZipPlugin must be instantiated with 'new'. Forgetting 'new' will not throw but will cause undefined behavior.","wrong":"plugins: [ZipPlugin({ filename: 'out.zip' })]","symbol":"new ZipPlugin({...})","correct":"plugins: [new ZipPlugin({ filename: 'out.zip' })]"},{"note":"Required if using path.join in pathMapper or other path operations in configuration.","wrong":"path is not imported","symbol":"path","correct":"const path = require('path');"}],"quickstart":{"code":"const path = require('path');\nconst ZipPlugin = require('zip-webpack-plugin');\n\nmodule.exports = {\n  mode: 'production',\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js'\n  },\n  plugins: [\n    new ZipPlugin({\n      filename: 'app.zip',\n      pathPrefix: 'static/',\n      include: [/\\\\.js$/, /\\\\.css$/],\n      exclude: [/\\\\.map$/],\n      fileOptions: {\n        compress: true,\n        mtime: new Date()\n      },\n      zipOptions: {\n        forceZip64Format: false\n      }\n    })\n  ]\n};","lang":"javascript","description":"Shows typical Webpack 5 configuration with ZipPlugin: entry, output, and plugin options for filtering assets, setting path prefix, and compression."},"warnings":[{"fix":"Upgrade to Node >= 10 or stay on v3.x (which supports Node 8+).","message":"v4.0.0 drops support for Node < 10.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"For Webpack 3, use v2.0.0: npm install zip-webpack-plugin@2.0.0","message":"v3.0.0 drops Webpack 3 support; requires Webpack 4+.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade to v4.0.1 or later.","message":"When using Webpack 5, the plugin runs at a later stage to pick up changes from other plugins (v4.0.1+). In earlier v4.x, some plugin modifications might be missed.","severity":"gotcha","affected_versions":">=4.0.0 <4.0.1"},{"fix":"No fix needed; just ensure the path is correct.","message":"The 'path' option can be relative to the Webpack output path. In v4, absolute paths are also allowed, but relative paths are the most common pattern.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Explicitly disable persistent caching or ensure the plugin re-runs (e.g., using cache.version).","message":"The plugin does not work with Webpack 5's persistent caching by default; assets may not be zipped on cache hits.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev zip-webpack-plugin` in the project root.","cause":"Package not installed or missing in node_modules.","error":"Error: Cannot find module 'zip-webpack-plugin'"},{"fix":"Use `const ZipPlugin = require('zip-webpack-plugin');` then `new ZipPlugin({...})` in plugins array.","cause":"ZipPlugin imported incorrectly or not instantiated with 'new'.","error":"TypeError: ZipPlugin is not a constructor"},{"fix":"Change `plugins: [ZipPlugin({...})]` to `plugins: [new ZipPlugin({...})]`.","cause":"Forgot to instantiate ZipPlugin with 'new'.","error":"ValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.plugins[0] should be a function."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}