diff --git a/README.md b/README.md index 662ddd2..67318a7 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ And run `webpack` via your preferred method. | **[`threshold`](#threshold)** | `{Number}` | `0` | Only assets bigger than this size are processed (in bytes) | | **[`minRatio`](#minratio)** | `{Number}` | `0.8` | Only assets that compress better than this ratio are processed (`minRatio = Compressed Size / Original Size`) | | **[`filename`](#filename)** | `{String\|Function}` | `[path][base].gz` | The target asset filename | -| **[`deleteOriginalAssets`](#deleteoriginalassets)** | `{Boolean}` | `false` | Whether to delete the original assets or not | +| **[`deleteOriginalAssets`](#deleteoriginalassets)** | `{Boolean\|'keep-source-map'}` | `false` | Whether to delete the original assets or not | | **[`cache`](#cache)** | `{Boolean}` | `true` | Enable file caching | ### `test` @@ -289,7 +289,7 @@ module.exports = { ### `deleteOriginalAssets` -Type: `Boolean` +Type: `Boolean | 'keep-source-map'` Default: `false` Whether to delete the original assets or not. @@ -306,6 +306,19 @@ module.exports = { }; ``` +To exclude sourcemaps from compression + +```js +module.exports = { + plugins: [ + new CompressionPlugin({ + exclude: /.map$/ + deleteOriginalAssets: 'keep-source-map', + }), + ], +}; +``` + ### `cache` > ⚠ Ignored in webpack 5! Please use https://webpack.js.org/configuration/other-options/#cache. diff --git a/package-lock.json b/package-lock.json index 7c6b0ba..6865de5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12402,9 +12402,9 @@ "dev": true }, "webpack": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.3.2.tgz", - "integrity": "sha512-DXsfHoI6lQAR3KnQh7+FsRfs9fs+TEvzXCA35UbKv4kVuzslg7QCMAcpFRZNDMjdtm9N/PoO54XEzGN9TeacQg==", + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.4.0.tgz", + "integrity": "sha512-udpYTyqz8toTTdaOsL2QKPLeZLt2IEm9qY7yTXuFEQhKu5bk0yQD9BtAdVQksmz4jFbbWOiWmm3NHarO0zr/ng==", "dev": true, "requires": { "@types/eslint-scope": "^3.7.0", diff --git a/package.json b/package.json index d255ff2..255595c 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.1.2", "standard-version": "^9.0.0", - "webpack": "^5.3.2" + "webpack": "^5.4.0" }, "keywords": [ "webpack" diff --git a/src/index.js b/src/index.js index 5c8f052..8208985 100644 --- a/src/index.js +++ b/src/index.js @@ -299,7 +299,21 @@ class CompressionPlugin { } if (this.options.deleteOriginalAssets) { - // eslint-disable-next-line no-param-reassign + if (this.options.deleteOriginalAssets === 'keep-source-map') { + // TODO `...` required only for webpack@4 + const updatedAssetInfo = { + ...info, + related: { ...info.related, sourceMap: null }, + }; + + CompressionPlugin.updateAsset( + compilation, + name, + inputSource, + updatedAssetInfo + ); + } + CompressionPlugin.deleteAsset(compilation, name); } else { // TODO `...` required only for webpack@4 diff --git a/src/options.json b/src/options.json index 8f28393..303cb5e 100644 --- a/src/options.json +++ b/src/options.json @@ -85,7 +85,15 @@ }, "deleteOriginalAssets": { "description": "Whether to delete the original assets or not.", - "type": "boolean" + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string", + "enum": ["keep-source-map"] + } + ] }, "filename": { "description": "The target asset filename.", diff --git a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 index 38a7259..63b9f13 100644 --- a/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 +++ b/test/__snapshots__/CompressionPlugin.test.js.snap.webpack5 @@ -24,11 +24,11 @@ Array [ ], Array [ "main.js", - 16407, + 16408, ], Array [ "main.js.gz", - 3845, + 3846, ], ] `; @@ -57,11 +57,11 @@ Array [ ], Array [ "main.js", - 16407, + 16408, ], Array [ "main.js.gz", - 3845, + 3846, ], ] `; @@ -97,12 +97,12 @@ Array [ 179, ], Array [ - "main.78a615f0242459e9f81e.js", - 16494, + "main.f7eb83969c330f73f483.js", + 16495, ], Array [ - "main.78a615f0242459e9f81e.js.gz", - 3931, + "main.f7eb83969c330f73f483.js.gz", + 3932, ], ] `; @@ -135,11 +135,11 @@ Array [ ], Array [ "main.js", - 16463, + 16464, ], Array [ "main.js.gz", - 3910, + 3911, ], ] `; @@ -172,11 +172,11 @@ Array [ ], Array [ "main.js", - 16447, + 16448, ], Array [ "main.js.gz", - 3906, + 3907, ], ] `; @@ -205,11 +205,11 @@ Array [ ], Array [ "main.js", - 16469, + 16470, ], Array [ "main.js.gz", - 3918, + 3919, ], ] `; @@ -266,19 +266,19 @@ Array [ ], Array [ "main.js", - 16447, + 16448, ], Array [ "main.js.br", - 3397, + 3401, ], Array [ "main.js.custom", - 16447, + 16448, ], Array [ "main.js.gz", - 3906, + 3907, ], ] `; @@ -327,19 +327,19 @@ Array [ ], Array [ "main.js", - 16447, + 16448, ], Array [ "main.js.br", - 3397, + 3401, ], Array [ "main.js.custom", - 16447, + 16448, ], Array [ "main.js.gz", - 3906, + 3907, ], ] `; @@ -376,11 +376,11 @@ Array [ ], Array [ "main.js", - 16447, + 16448, ], Array [ "main.js.gz", - 3906, + 3907, ], ] `; @@ -409,11 +409,11 @@ Array [ ], Array [ "main.js", - 16447, + 16448, ], Array [ "main.js.gz", - 3906, + 3907, ], ] `; @@ -449,12 +449,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -482,12 +482,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -542,10 +542,10 @@ Array [ }, ], Array [ - "async.async.js?ver=fb923fbfbe1905de10cc", + "async.async.js?ver=1bd91a991e7113ab51ef", 265, Object { - "fullhash": "fb923fbfbe1905de10cc", + "fullhash": "1bd91a991e7113ab51ef", "immutable": true, "javascriptModule": false, "related": Object { @@ -575,24 +575,24 @@ Array [ ], Array [ "main.js.gz", - 3952, + 3953, Object { "compressed": true, "immutable": true, - "size": 3952, + "size": 3953, }, ], Array [ - "main.js?var=fb923fbfbe1905de10cc", - 16650, + "main.js?var=1bd91a991e7113ab51ef", + 16651, Object { - "fullhash": "fb923fbfbe1905de10cc", + "fullhash": "1bd91a991e7113ab51ef", "immutable": true, "javascriptModule": false, "related": Object { "gziped": "main.js.gz", }, - "size": 16650, + "size": 16651, }, ], ] @@ -644,10 +644,10 @@ Array [ }, ], Array [ - "async.async.js?ver=de308cf9f862aae72c20", + "async.async.js?ver=6c385e59eb34d690245b", 265, Object { - "fullhash": "de308cf9f862aae72c20", + "fullhash": "6c385e59eb34d690245b", "immutable": true, "javascriptModule": false, "related": Object { @@ -677,44 +677,44 @@ Array [ ], Array [ "main.js.gz", - 3987, + 3990, Object { "compressed": true, "immutable": true, - "size": 3987, + "size": 3990, }, ], Array [ "main.js.map.gz", - 3960, + 3962, Object { "compressed": true, - "size": 3960, + "size": 3962, }, ], Array [ - "main.js.map?var=de308cf9f862aae72c20", - 12447, + "main.js.map?var=6c385e59eb34d690245b", + 12453, Object { "development": true, "related": Object { "gziped": "main.js.map.gz", }, - "size": 12447, + "size": 12453, }, ], Array [ - "main.js?var=de308cf9f862aae72c20", - 16711, + "main.js?var=6c385e59eb34d690245b", + 16712, Object { - "fullhash": "de308cf9f862aae72c20", + "fullhash": "6c385e59eb34d690245b", "immutable": true, "javascriptModule": false, "related": Object { "gziped": "main.js.gz", - "sourceMap": "main.js.map?var=de308cf9f862aae72c20", + "sourceMap": "main.js.map?var=6c385e59eb34d690245b", }, - "size": 16711, + "size": 16712, }, ], ] @@ -845,10 +845,10 @@ Array [ }, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, Object { - "fullhash": "f7d7a6b10217e2699ecc", + "fullhash": "332db2bcb6b6f299224f", "immutable": true, "javascriptModule": false, "related": Object { @@ -862,45 +862,45 @@ Array [ ], Array [ "main.js.br", - 3442, + 3446, Object { "compressed": true, "immutable": true, - "size": 3442, + "size": 3446, }, ], Array [ "main.js.compress", - 16653, + 16654, Object { "compressed": true, "immutable": true, - "size": 16653, + "size": 16654, }, ], Array [ "main.js.custom?foo=bar#hash", - 16653, + 16654, Object { "compressed": true, "immutable": true, - "size": 16653, + "size": 16654, }, ], Array [ "main.js.gz", - 3957, + 3959, Object { "compressed": true, "immutable": true, - "size": 3957, + "size": 3959, }, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, Object { - "fullhash": "f7d7a6b10217e2699ecc", + "fullhash": "332db2bcb6b6f299224f", "immutable": true, "javascriptModule": false, "related": Object { @@ -909,7 +909,7 @@ Array [ "customed": "main.js.custom?foo=bar#hash", "gziped": "main.js.gz", }, - "size": 16653, + "size": 16654, }, ], ] @@ -938,16 +938,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; diff --git a/test/__snapshots__/algorithm.test.js.snap.webpack5 b/test/__snapshots__/algorithm.test.js.snap.webpack5 index a8ce411..a422f77 100644 --- a/test/__snapshots__/algorithm.test.js.snap.webpack5 +++ b/test/__snapshots__/algorithm.test.js.snap.webpack5 @@ -27,12 +27,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -70,12 +70,12 @@ Array [ 265, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 16494, + "main.c9c6c970f01f9eb6d301.js.gz", + 16495, ], ] `; @@ -107,8 +107,8 @@ Array [ 265, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], ] `; diff --git a/test/__snapshots__/cache-option.test.js.snap.webpack5 b/test/__snapshots__/cache-option.test.js.snap.webpack5 index 73cd31e..4db26be 100644 --- a/test/__snapshots__/cache-option.test.js.snap.webpack5 +++ b/test/__snapshots__/cache-option.test.js.snap.webpack5 @@ -23,12 +23,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -56,12 +56,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -97,12 +97,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -130,12 +130,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -171,12 +171,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -204,12 +204,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -245,12 +245,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -278,12 +278,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; diff --git a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 index 01ba6bd..c2464d6 100644 --- a/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 +++ b/test/__snapshots__/compressionOptions-option.test.js.snap.webpack5 @@ -27,12 +27,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -68,12 +68,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -105,12 +105,12 @@ Array [ 146, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3419, + "main.c9c6c970f01f9eb6d301.js.gz", + 3422, ], ] `; @@ -142,12 +142,12 @@ Array [ 167, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3921, + "main.c9c6c970f01f9eb6d301.js.gz", + 3922, ], ] `; @@ -179,12 +179,12 @@ Array [ 161, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3915, + "main.c9c6c970f01f9eb6d301.js.gz", + 3916, ], ] `; @@ -216,12 +216,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; diff --git a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 index b822eab..029009c 100644 --- a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 +++ b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack4 @@ -1,5 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 393, + ], + Array [ + "async.async.dcbdb1dd40763448b635.js", + 220, + ], + Array [ + "async.async.dcbdb1dd40763448b635.js.map", + 132, + ], + Array [ + "main.82c6786e32f9c77b44ef.js", + 3044, + ], + Array [ + "main.82c6786e32f9c77b44ef.js.map", + 10291, + ], +] +`; + +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': errors 1`] = `Array []`; + +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': warnings 1`] = `Array []`; + exports[`"deleteOriginalAssets" option should work and delete original assets: assets 1`] = ` Array [ Array [ diff --git a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 index 4c2564c..1525007 100644 --- a/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 +++ b/test/__snapshots__/deleteOriginalAssets.test.js.snap.webpack5 @@ -1,5 +1,34 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': assets 1`] = ` +Array [ + Array [ + "09a1a1112c577c2794359715edfcb5ac.png", + 78117, + ], + Array [ + "23fc1d3ac606d117e05a140e0de79806.svg", + 393, + ], + Array [ + "async.async.1c2911c7c819fc826fb7.js", + 179, + ], + Array [ + "main.6b42eac1865a72d65938.js", + 3976, + ], + Array [ + "main.6b42eac1865a72d65938.js.map", + 12336, + ], +] +`; + +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': errors 1`] = `Array []`; + +exports[`"deleteOriginalAssets" option should delete original assets and keep source maps with option 'keep-source-map': warnings 1`] = `Array []`; + exports[`"deleteOriginalAssets" option should work and delete original assets: assets 1`] = ` Array [ Array [ @@ -15,8 +44,8 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -40,8 +69,8 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 3933, + "main.c9c6c970f01f9eb6d301.js", + 3934, ], ] `; @@ -73,12 +102,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -114,12 +143,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -143,8 +172,8 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 3933, + "main.c9c6c970f01f9eb6d301.js", + 3934, ], ] `; @@ -153,7 +182,7 @@ exports[`"deleteOriginalAssets" option should work and report errors on duplicat Array [ "Error: Conflict: Multiple assets emit different content to the same filename 23fc1d3ac606d117e05a140e0de79806.svg", "Error: Conflict: Multiple assets emit different content to the same filename async.async.9325220d444b0d653c03.js", - "Error: Conflict: Multiple assets emit different content to the same filename main.7cdd8fe3ccdaedc3726c.js", + "Error: Conflict: Multiple assets emit different content to the same filename main.c9c6c970f01f9eb6d301.js", ] `; diff --git a/test/__snapshots__/exclude-option.test.js.snap.webpack5 b/test/__snapshots__/exclude-option.test.js.snap.webpack5 index 333a391..f350511 100644 --- a/test/__snapshots__/exclude-option.test.js.snap.webpack5 +++ b/test/__snapshots__/exclude-option.test.js.snap.webpack5 @@ -19,16 +19,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; @@ -52,16 +52,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; diff --git a/test/__snapshots__/filename-option.test.js.snap.webpack5 b/test/__snapshots__/filename-option.test.js.snap.webpack5 index 2651c8f..a689143 100644 --- a/test/__snapshots__/filename-option.test.js.snap.webpack5 +++ b/test/__snapshots__/filename-option.test.js.snap.webpack5 @@ -19,20 +19,20 @@ Array [ 672, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ - "async.async.super-compressed.js.gz?ver=f7d7a6b10217e2699ecc", + "async.async.super-compressed.js.gz?ver=332db2bcb6b6f299224f", 179, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], Array [ - "main.super-compressed.js.gz?var=f7d7a6b10217e2699ecc", - 3957, + "main.super-compressed.js.gz?var=332db2bcb6b6f299224f", + 3959, ], ] `; @@ -60,20 +60,20 @@ Array [ 393, ], Array [ - "assets/js/async.async.js.super-compressed.gz?ver=0a9999404b9f21ff4239#hash", + "assets/js/async.async.js.super-compressed.gz?ver=38881eaf41c9852a6e24#hash", 179, ], Array [ - "assets/js/async.async.js?ver=0a9999404b9f21ff4239#hash", + "assets/js/async.async.js?ver=38881eaf41c9852a6e24#hash", 265, ], Array [ - "assets/js/main.js.super-compressed.gz?var=0a9999404b9f21ff4239#hash", - 3975, + "assets/js/main.js.super-compressed.gz?var=38881eaf41c9852a6e24#hash", + 3977, ], Array [ - "assets/js/main.js?var=0a9999404b9f21ff4239#hash", - 16679, + "assets/js/main.js?var=38881eaf41c9852a6e24#hash", + 16680, ], ] `; @@ -101,20 +101,20 @@ Array [ 393, ], Array [ - "async.async.js.gz?ver=8cd45e10c5b13cf32806", + "async.async.js.gz?ver=f5ffb51646e417dee948", 179, ], Array [ - "async.async.js?ver=8cd45e10c5b13cf32806#hash", + "async.async.js?ver=f5ffb51646e417dee948#hash", 265, ], Array [ - "main.js.gz?var=8cd45e10c5b13cf32806", - 3962, + "main.js.gz?var=f5ffb51646e417dee948", + 3964, ], Array [ - "main.js?var=8cd45e10c5b13cf32806#hash", - 16658, + "main.js?var=f5ffb51646e417dee948#hash", + 16659, ], ] `; @@ -146,7 +146,7 @@ Array [ 179, ], Array [ - "assets/scripts/async.async.js?ver=cc7401cacdc62b3e8755#hash", + "assets/scripts/async.async.js?ver=126e16de36baed6320ff#hash", 265, ], Array [ @@ -154,8 +154,8 @@ Array [ 3976, ], Array [ - "assets/scripts/main.js?var=cc7401cacdc62b3e8755#hash", - 16684, + "assets/scripts/main.js?var=126e16de36baed6320ff#hash", + 16685, ], ] `; diff --git a/test/__snapshots__/include-option.test.js.snap.webpack5 b/test/__snapshots__/include-option.test.js.snap.webpack5 index 27b2611..b684a85 100644 --- a/test/__snapshots__/include-option.test.js.snap.webpack5 +++ b/test/__snapshots__/include-option.test.js.snap.webpack5 @@ -15,16 +15,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; @@ -52,16 +52,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; diff --git a/test/__snapshots__/minRatio-option.test.js.snap.webpack5 b/test/__snapshots__/minRatio-option.test.js.snap.webpack5 index 4c8e544..9a6d5c0 100644 --- a/test/__snapshots__/minRatio-option.test.js.snap.webpack5 +++ b/test/__snapshots__/minRatio-option.test.js.snap.webpack5 @@ -15,8 +15,8 @@ Array [ 265, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], ] `; @@ -52,12 +52,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; diff --git a/test/__snapshots__/test-option.test.js.snap.webpack5 b/test/__snapshots__/test-option.test.js.snap.webpack5 index 5129070..6fa8cec 100644 --- a/test/__snapshots__/test-option.test.js.snap.webpack5 +++ b/test/__snapshots__/test-option.test.js.snap.webpack5 @@ -15,12 +15,12 @@ Array [ 672, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; @@ -48,12 +48,12 @@ Array [ 393, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; @@ -85,16 +85,16 @@ Array [ 179, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ "main.js.gz", - 3957, + 3959, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; @@ -114,12 +114,12 @@ Array [ 672, ], Array [ - "async.async.js?ver=f7d7a6b10217e2699ecc", + "async.async.js?ver=332db2bcb6b6f299224f", 265, ], Array [ - "main.js?var=f7d7a6b10217e2699ecc", - 16653, + "main.js?var=332db2bcb6b6f299224f", + 16654, ], ] `; diff --git a/test/__snapshots__/threshold-option.test.js.snap.webpack5 b/test/__snapshots__/threshold-option.test.js.snap.webpack5 index 8b69b0e..2bf4202 100644 --- a/test/__snapshots__/threshold-option.test.js.snap.webpack5 +++ b/test/__snapshots__/threshold-option.test.js.snap.webpack5 @@ -27,12 +27,12 @@ Array [ 179, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -60,12 +60,12 @@ Array [ 265, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js", - 16494, + "main.c9c6c970f01f9eb6d301.js", + 16495, ], Array [ - "main.7cdd8fe3ccdaedc3726c.js.gz", - 3933, + "main.c9c6c970f01f9eb6d301.js.gz", + 3934, ], ] `; @@ -81,12 +81,12 @@ Array [ 0, ], Array [ - "main.27cbd0a71f6476e80306.js", - 5896, + "main.a175a5dade10e10b9117.js", + 5897, ], Array [ - "main.27cbd0a71f6476e80306.js.gz", - 1608, + "main.a175a5dade10e10b9117.js.gz", + 1609, ], ] `; @@ -106,12 +106,12 @@ Array [ 20, ], Array [ - "main.27cbd0a71f6476e80306.js", - 5896, + "main.a175a5dade10e10b9117.js", + 5897, ], Array [ - "main.27cbd0a71f6476e80306.js.gz", - 1608, + "main.a175a5dade10e10b9117.js.gz", + 1609, ], ] `; diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index eac0be6..a401952 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -29,8 +29,12 @@ exports[`validate options should throw an error on the "compressionOptions" opti exports[`validate options should throw an error on the "deleteOriginalAssets" option with "true" value 1`] = ` "Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema. - - options.deleteOriginalAssets should be a boolean. - -> Whether to delete the original assets or not." + - options.deleteOriginalAssets should be one of these: + boolean | \\"keep-source-map\\" + -> Whether to delete the original assets or not. + Details: + * options.deleteOriginalAssets should be a boolean. + * options.deleteOriginalAssets should be \\"keep-source-map\\"." `; exports[`validate options should throw an error on the "exclude" option with "[{},"foo",true]" value 1`] = ` diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index eac0be6..a401952 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -29,8 +29,12 @@ exports[`validate options should throw an error on the "compressionOptions" opti exports[`validate options should throw an error on the "deleteOriginalAssets" option with "true" value 1`] = ` "Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema. - - options.deleteOriginalAssets should be a boolean. - -> Whether to delete the original assets or not." + - options.deleteOriginalAssets should be one of these: + boolean | \\"keep-source-map\\" + -> Whether to delete the original assets or not. + Details: + * options.deleteOriginalAssets should be a boolean. + * options.deleteOriginalAssets should be \\"keep-source-map\\"." `; exports[`validate options should throw an error on the "exclude" option with "[{},"foo",true]" value 1`] = ` diff --git a/test/deleteOriginalAssets.test.js b/test/deleteOriginalAssets.test.js index e0792e4..242b673 100644 --- a/test/deleteOriginalAssets.test.js +++ b/test/deleteOriginalAssets.test.js @@ -84,4 +84,26 @@ describe('"deleteOriginalAssets" option', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it(`should delete original assets and keep source maps with option 'keep-source-map'`, async () => { + compiler = getCompiler( + './entry.js', + {}, + { + devtool: 'source-map', + } + ); + + new CompressionPlugin({ + filename: '[file]', + exclude: /.map$/, + deleteOriginalAssets: 'keep-source-map', + }).apply(compiler); + + const stats = await compile(compiler); + + expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); });