From f48852d583fd8595d2551a50368338289fc1f138 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 18 Sep 2026 18:21:21 +0000 Subject: [PATCH 1/2] docs: deprecate in favour of minimizer-webpack-plugin Compression ships there now, as an asset generator, and two bugs open here are fixed by it. The README says what each option maps to. --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 31c193e..bbf6056 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,82 @@ Prepare compressed versions of assets to serve them with Content-Encoding. +> [!WARNING] +> +> **This plugin is deprecated.** Compression now ships with +> [`minimizer-webpack-plugin`](https://github.com/webpack/minimizer-webpack-plugin#compress), +> which reads, writes, caches and schedules assets for every kind of transform, +> so minifying and compressing are one plugin over one pass and one cache. It +> also fixes two long-standing bugs here — deleting an original no longer takes +> the files named in its `related` info, so a second compression instance keeps +> its output ([#245](https://github.com/webpack/compression-webpack-plugin/issues/245), +> [#389](https://github.com/webpack/compression-webpack-plugin/issues/389)) — +> and runs the work in a worker pool +> ([#408](https://github.com/webpack/compression-webpack-plugin/issues/408)). +> +> See [Migrating](#migrating) below. + +## Migrating + +`minimizer-webpack-plugin` compresses through an `asset` generator, which writes +the compressed file beside the one it read. Every option here has a home there: + +```js +const MinimizerPlugin = require("minimizer-webpack-plugin"); + +module.exports = { + optimization: { + minimize: true, + minimizer: [ + new MinimizerPlugin({ + test: /\.(js|css|html|svg)$/i, + generate: { + implementation: MinimizerPlugin.compress, + options: { algorithm: "gzip", compressionOptions: { level: 9 } }, + type: "asset", + filename: "[path][base].gz", + threshold: 10240, + minRatio: 0.8, + relatedName: "gzipped", + deleteOriginalAssets: false, + }, + }), + ], + }, +}; +``` + +| `compression-webpack-plugin` | `minimizer-webpack-plugin` | +| :-------------------------------------------------- | :------------------------------------ | +| `test` / `include` / `exclude` | the same, on the plugin | +| `algorithm` | `generate.options.algorithm` | +| `compressionOptions` | `generate.options.compressionOptions` | +| `filename` | `generate.filename` | +| `threshold` | `generate.threshold` | +| `minRatio` | `generate.minRatio` | +| `deleteOriginalAssets` | `generate.deleteOriginalAssets` | +| the `gzipped` / `brotliCompressed` key in `related` | `generate.relatedName` | + +That instance minifies as well, since `minify` defaults to terser. To compress +and change nothing, say so with an empty list of minimizers — and state `test`, +whose `.js` default belongs to minifying: + +```js +new MinimizerPlugin({ + test: /.*/, + minify: [], + generate: { + implementation: MinimizerPlugin.compress, + options: { algorithm: "gzip" }, + type: "asset", + filename: "[path][base].gz", + }, +}); +``` + +Two algorithms are two named generators rather than two plugins — see +[Compressing with minifying, and without](https://github.com/webpack/minimizer-webpack-plugin#compressing-with-minifying-and-without). + ## Getting Started To begin, you'll need to install `compression-webpack-plugin`: diff --git a/package.json b/package.json index 9e2be61..85e3517 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "compression-webpack-plugin", "version": "12.0.0", - "description": "Prepare compressed versions of assets to serve them with Content-Encoding", + "description": "Deprecated - use minimizer-webpack-plugin instead. Prepare compressed versions of assets to serve them with Content-Encoding", "keywords": [ "webpack" ], From ed0811c4c40fc16ba27162983a9c80293bdbadd0 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Sat, 19 Sep 2026 12:39:17 +0000 Subject: [PATCH 2/2] docs: say which version the migration needs, and drop the worker claim Compressing runs in the webpack process there too, since the bytes have no way across to a worker; the delete and the function forms arrive in 5.11.0. --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bbf6056..0ab79b5 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,26 @@ Prepare compressed versions of assets to serve them with Content-Encoding. > **This plugin is deprecated.** Compression now ships with > [`minimizer-webpack-plugin`](https://github.com/webpack/minimizer-webpack-plugin#compress), > which reads, writes, caches and schedules assets for every kind of transform, -> so minifying and compressing are one plugin over one pass and one cache. It -> also fixes two long-standing bugs here — deleting an original no longer takes -> the files named in its `related` info, so a second compression instance keeps -> its output ([#245](https://github.com/webpack/compression-webpack-plugin/issues/245), -> [#389](https://github.com/webpack/compression-webpack-plugin/issues/389)) — -> and runs the work in a worker pool -> ([#408](https://github.com/webpack/compression-webpack-plugin/issues/408)). +> so minifying and compressing are one plugin over one pass and one cache. From +> **5.11.0** it also fixes two long-standing bugs here: deleting an original +> takes that file alone, so the source map and a second compression instance's +> output both survive +> ([#245](https://github.com/webpack/compression-webpack-plugin/issues/245), +> [#389](https://github.com/webpack/compression-webpack-plugin/issues/389)). > > See [Migrating](#migrating) below. ## Migrating `minimizer-webpack-plugin` compresses through an `asset` generator, which writes -the compressed file beside the one it read. Every option here has a home there: +the compressed file beside the one it read. Install it first — this package does +not depend on it: + +```console +npm install minimizer-webpack-plugin --save-dev +``` + +Every option here has a home there, from **5.11.0** onwards: ```js const MinimizerPlugin = require("minimizer-webpack-plugin"); @@ -71,6 +77,12 @@ module.exports = { | `deleteOriginalAssets` | `generate.deleteOriginalAssets` | | the `gzipped` / `brotliCompressed` key in `related` | `generate.relatedName` | +`filename` and `deleteOriginalAssets` take a function there from 5.11.0, and +`deleteOriginalAssets: true` keeps the source map, so `"keep-source-map"` is +what `true` does rather than a value to carry over. On 5.10.x both are what +they were — a string and a boolean — and deleting an original takes the files +named in its `related` info with it. + That instance minifies as well, since `minify` defaults to terser. To compress and change nothing, say so with an empty list of minimizers — and state `test`, whose `.js` default belongs to minifying: