From 52c1aef218923b716a0b25433e7d916c5bb6c805 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Mon, 29 Aug 2022 21:13:47 +0300 Subject: [PATCH 1/2] fix: allow disable compress options for `terser` and `swc` (#514) --- src/utils.js | 52 +++++++++++-------- test/__snapshots__/minify-option.test.js.snap | 13 +++++ .../terserOptions-option.test.js.snap | 5 +- test/minify-option.test.js | 17 ++++++ 4 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/utils.js b/src/utils.js index 7db615a..1c7c3d5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -228,7 +228,9 @@ async function terserMinify( ...terserOptions, compress: typeof terserOptions.compress === "boolean" - ? {} + ? terserOptions.compress + ? {} + : false : { ...terserOptions.compress }, // ecma: terserOptions.ecma, // ie8: terserOptions.ie8, @@ -281,17 +283,19 @@ async function terserMinify( ); } - // More optimizations - if (typeof terserOptions.compress.ecma === "undefined") { - terserOptions.compress.ecma = terserOptions.ecma; - } + if (terserOptions.compress) { + // More optimizations + if (typeof terserOptions.compress.ecma === "undefined") { + terserOptions.compress.ecma = terserOptions.ecma; + } - // https://github.com/webpack/webpack/issues/16135 - if ( - terserOptions.ecma === 5 && - typeof terserOptions.compress.arrows === "undefined" - ) { - terserOptions.compress.arrows = false; + // https://github.com/webpack/webpack/issues/16135 + if ( + terserOptions.ecma === 5 && + typeof terserOptions.compress.arrows === "undefined" + ) { + terserOptions.compress.arrows = false; + } } const [[filename, code]] = Object.entries(input); @@ -558,7 +562,9 @@ async function swcMinify(input, sourceMap, minimizerOptions) { ...swcOptions, compress: typeof swcOptions.compress === "boolean" - ? {} + ? swcOptions.compress + ? {} + : false : { ...swcOptions.compress }, mangle: swcOptions.mangle == null @@ -588,17 +594,19 @@ async function swcMinify(input, sourceMap, minimizerOptions) { swcOptions.sourceMap = true; } - // More optimizations - if (typeof swcOptions.compress.ecma === "undefined") { - swcOptions.compress.ecma = swcOptions.ecma; - } + if (swcOptions.compress) { + // More optimizations + if (typeof swcOptions.compress.ecma === "undefined") { + swcOptions.compress.ecma = swcOptions.ecma; + } - // https://github.com/webpack/webpack/issues/16135 - if ( - swcOptions.ecma === 5 && - typeof swcOptions.compress.arrows === "undefined" - ) { - swcOptions.compress.arrows = false; + // https://github.com/webpack/webpack/issues/16135 + if ( + swcOptions.ecma === 5 && + typeof swcOptions.compress.arrows === "undefined" + ) { + swcOptions.compress.arrows = false; + } } const [[filename, code]] = Object.entries(input); diff --git a/test/__snapshots__/minify-option.test.js.snap b/test/__snapshots__/minify-option.test.js.snap index 4720acb..139f652 100644 --- a/test/__snapshots__/minify-option.test.js.snap +++ b/test/__snapshots__/minify-option.test.js.snap @@ -178,6 +178,19 @@ exports[`minify option should work using when the \`minify\` option is \`terserM exports[`minify option should work using when the \`minify\` option is \`terserMinify\` and ECMA modules output: warnings 1`] = `Array []`; +exports[`minify option should work using when the \`minify\` option is \`terserMinify\` and allows to disable \`compress\` options: assets 1`] = ` +Object { + "main.js": "/*! For license information please see main.js.LICENSE.txt */ +(()=>{var r={791:r=>{const n=null&&2+2;r.exports=function r(){const n=2+2;console.log(n+1+2)}}};var n={};function o(t){var e=n[t];if(e!==undefined){return e.exports}var s=n[t]={exports:{}};r[t](s,s.exports,o);return s.exports}var t=o(791)})();", + "main.js.LICENSE.txt": "/* @preserve*/ +", +} +`; + +exports[`minify option should work using when the \`minify\` option is \`terserMinify\` and allows to disable \`compress\` options: errors 1`] = `Array []`; + +exports[`minify option should work using when the \`minify\` option is \`terserMinify\` and allows to disable \`compress\` options: warnings 1`] = `Array []`; + exports[`minify option should work using when the \`minify\` option is \`terserMinify\` and allows to set \`terser\` options: assets 1`] = ` Object { "main.js": "(()=>{var __webpack_modules__={791:module=>{module.exports=function(){console.log(7)}}},__webpack_module_cache__={};(function __webpack_require__(moduleId){var cachedModule=__webpack_module_cache__[moduleId];if(void 0!==cachedModule)return cachedModule.exports;var module=__webpack_module_cache__[moduleId]={exports:{}};return __webpack_modules__[moduleId](module,module.exports,__webpack_require__),module.exports})(791)})();", diff --git a/test/__snapshots__/terserOptions-option.test.js.snap b/test/__snapshots__/terserOptions-option.test.js.snap index d396f66..c40894f 100644 --- a/test/__snapshots__/terserOptions-option.test.js.snap +++ b/test/__snapshots__/terserOptions-option.test.js.snap @@ -12,7 +12,10 @@ exports[`terserOptions option should match snapshot for the "compress" option wi exports[`terserOptions option should match snapshot for the "compress" option with the "false" value: assets 1`] = ` Object { - "main.js": "(()=>{var r={791:r=>{r.exports=function(){console.log(7)}}},o={};(function t(e){var n=o[e];if(void 0!==n)return n.exports;var s=o[e]={exports:{}};return r[e](s,s.exports,t),s.exports})(791)})();", + "main.js": "/*! For license information please see main.js.LICENSE.txt */ +(()=>{var r={791:r=>{const n=null&&2+2;r.exports=function r(){const n=2+2;console.log(n+1+2)}}};var n={};function o(t){var e=n[t];if(e!==undefined){return e.exports}var s=n[t]={exports:{}};r[t](s,s.exports,o);return s.exports}var t=o(791)})();", + "main.js.LICENSE.txt": "/* @preserve*/ +", } `; diff --git a/test/minify-option.test.js b/test/minify-option.test.js index d05cc1d..d86241f 100644 --- a/test/minify-option.test.js +++ b/test/minify-option.test.js @@ -447,6 +447,23 @@ describe("minify option", () => { expect(getWarnings(stats)).toMatchSnapshot("warnings"); }); + it("should work using when the `minify` option is `terserMinify` and allows to disable `compress` options", async () => { + const compiler = getCompiler(); + + new TerserPlugin({ + minify: TerserPlugin.terserMinify, + terserOptions: { + compress: false, + }, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(readsAssets(compiler, stats)).toMatchSnapshot("assets"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + }); + it("should work using when the `minify` option is `uglifyJsMinify`", async () => { const compiler = getCompiler({ target: ["web", "es5"], From 9718859ada5693b41d5410329a52331e14f4ebd7 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 29 Aug 2022 21:14:07 +0300 Subject: [PATCH 2/2] chore(release): 5.3.6 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d84046..879e482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [5.3.6](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v5.3.5...v5.3.6) (2022-08-29) + + +### Bug Fixes + +* allow disable compress options for `terser` and `swc` ([#514](https://github.com/webpack-contrib/terser-webpack-plugin/issues/514)) ([52c1aef](https://github.com/webpack-contrib/terser-webpack-plugin/commit/52c1aef218923b716a0b25433e7d916c5bb6c805)) + ### [5.3.5](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v5.3.4...v5.3.5) (2022-08-16) diff --git a/package-lock.json b/package-lock.json index 3303c82..9a79f52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "terser-webpack-plugin", - "version": "5.3.5", + "version": "5.3.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "terser-webpack-plugin", - "version": "5.3.5", + "version": "5.3.6", "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "^0.3.14", diff --git a/package.json b/package.json index 943724d..e0cc051 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "terser-webpack-plugin", - "version": "5.3.5", + "version": "5.3.6", "description": "Terser plugin for webpack", "license": "MIT", "repository": "webpack-contrib/terser-webpack-plugin",