You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce `minimizerOptions` as the canonical name for the options that
are forwarded to the active minimizer (Terser by default, or whatever
function is supplied via `minify`). The previous `terserOptions` key
keeps working as a deprecated alias; passing both at the same time now
throws an explicit error.
Schema, JSDoc-derived TypeScript declarations, README examples and tests
have been updated to favour the new name while still validating the old
one.
@@ -287,7 +287,7 @@ Allows you to override the default minify function.
287
287
By default plugin uses [terser](https://github.com/terser/terser) package.
288
288
Useful for using and testing unpublished versions or forks.
289
289
290
-
An array of functions can also be provided to chain multiple minimizers — the output of each minimizer is fed as input to the next. When an array is used, the [`terserOptions`](#terseroptions) option may also be an array (index-paired with `minify`) or a single object that is reused for every minimizer.
290
+
An array of functions can also be provided to chain multiple minimizers — the output of each minimizer is fed as input to the next. When an array is used, the [`minimizerOptions`](#minimizeroptions) option may also be an array (index-paired with `minify`) or a single object that is reused for every minimizer.
291
291
292
292
> **Warning**
293
293
>
@@ -300,7 +300,7 @@ An array of functions can also be provided to chain multiple minimizers — the
When the [`minify`](#minify) option is an array of minimizers, `terserOptions`
408
+
When the [`minify`](#minify) option is an array of minimizers, `minimizerOptions`
408
409
can also be an array. Each element is passed to the minimizer at the same
409
410
index in the `minify` array. If a single object is provided instead, it is
410
411
reused for every minimizer.
411
412
413
+
> **Note**
414
+
>
415
+
> `terserOptions` is kept as a deprecated alias of `minimizerOptions` for
416
+
> backwards compatibility — passing either is equivalent. Passing both at the
417
+
> same time throws an error. Prefer `minimizerOptions` in new code.
418
+
412
419
**webpack.config.js**
413
420
414
421
```js
@@ -417,7 +424,7 @@ module.exports = {
417
424
minimize:true,
418
425
minimizer: [
419
426
newTerserPlugin({
420
-
terserOptions: {
427
+
minimizerOptions: {
421
428
ecma:undefined,
422
429
parse: {},
423
430
compress: {},
@@ -492,7 +499,7 @@ By default, extract only comments using `/^\**!|@preserve|@license|@cc_on/i` Reg
492
499
493
500
If the original file is named `foo.js`, then the comments will be stored to `foo.js.LICENSE.txt`.
494
501
495
-
The `terserOptions.format.comments` option specifies whether the comment will be preserved - i.e., it is possible to preserve some comments (e.g. annotations) while extracting others, or even preserve comments that have already been extracted.
502
+
The `minimizerOptions.format.comments` option specifies whether the comment will be preserved - i.e., it is possible to preserve some comments (e.g. annotations) while extracting others, or even preserve comments that have already been extracted.
496
503
497
504
#### `boolean`
498
505
@@ -741,7 +748,7 @@ module.exports = {
741
748
minimize:true,
742
749
minimizer: [
743
750
newTerserPlugin({
744
-
terserOptions: {
751
+
minimizerOptions: {
745
752
format: {
746
753
comments:/@license/i,
747
754
},
@@ -765,7 +772,7 @@ module.exports = {
765
772
minimize:true,
766
773
minimizer: [
767
774
newTerserPlugin({
768
-
terserOptions: {
775
+
minimizerOptions: {
769
776
format: {
770
777
comments:false,
771
778
},
@@ -790,9 +797,9 @@ module.exports = {
790
797
minimizer: [
791
798
newTerserPlugin({
792
799
minify:TerserPlugin.uglifyJsMinify,
793
-
// `terserOptions` options will be passed to `uglify-js`
800
+
// `minimizerOptions` will be passed to `uglify-js`
794
801
// Link to options - https://github.com/mishoo/UglifyJS#minify-options
795
-
terserOptions: {},
802
+
minimizerOptions: {},
796
803
}),
797
804
],
798
805
},
@@ -818,9 +825,9 @@ module.exports = {
818
825
minimizer: [
819
826
newTerserPlugin({
820
827
minify:TerserPlugin.swcMinify,
821
-
// `terserOptions` options will be passed to `swc` (`@swc/core`)
828
+
// `minimizerOptions` will be passed to `swc` (`@swc/core`)
822
829
// Link to options - https://swc.rs/docs/config-js-minify
823
-
terserOptions: {},
830
+
minimizerOptions: {},
824
831
}),
825
832
],
826
833
},
@@ -844,16 +851,16 @@ module.exports = {
844
851
minimizer: [
845
852
newTerserPlugin({
846
853
minify:TerserPlugin.esbuildMinify,
847
-
// `terserOptions` options will be passed to `esbuild`
854
+
// `minimizerOptions` will be passed to `esbuild`
848
855
// Link to options - https://esbuild.github.io/api/#minify
849
856
// Note: the `minify` options is true by default (and override other `minify*` options), so if you want to disable the `minifyIdentifiers` option (or other `minify*` options) please use:
850
-
//terserOptions: {
857
+
//minimizerOptions: {
851
858
// minify: false,
852
859
// minifyWhitespace: true,
853
860
// minifyIdentifiers: false,
854
861
// minifySyntax: true,
855
862
// },
856
-
terserOptions: {},
863
+
minimizerOptions: {},
857
864
}),
858
865
],
859
866
},
@@ -878,7 +885,7 @@ module.exports = {
878
885
test:/\.json$/,
879
886
minify:TerserPlugin.jsonMinify,
880
887
// We are supporting `space` and `replacer` options, you can set them below
"The `minimizerOptions` and `terserOptions` options can't be used together. Please use only `minimizerOptions` (`terserOptions` is a deprecated alias).",
"Invalid options object. Terser Plugin has been initialized using an options object that does not match the API schema.
221
+
- options.minimizerOptions should be a non-empty array."
217
222
`;
223
+
224
+
exports[`validation validate 19`] =`
225
+
"Invalid options object. Terser Plugin has been initialized using an options object that does not match the API schema.
226
+
- options.minimizerOptions should be one of these:
227
+
object { … } | [object { … }, ...] (should not have fewer than 1 item)
228
+
-> Options for \`terser\` (by default) or custom \`minify\` function.
229
+
-> Read more at https://github.com/webpack/terser-webpack-plugin#minimizeroptions
230
+
Details:
231
+
* options.minimizerOptions should be an object:
232
+
object { … }
233
+
* options.minimizerOptions should be an array:
234
+
[object { … }, ...] (should not have fewer than 1 item)"
235
+
`;
236
+
237
+
exports[`validation validate 20`] =`"The \`minimizerOptions\` and \`terserOptions\` options can't be used together. Please use only \`minimizerOptions\` (\`terserOptions\` is a deprecated alias)."`;
0 commit comments