This plugin is used to minify JavaScript files using SWC.
Use this plugin via optimization.minimizer:
When optimization.minimizer
is set, the default minimizers are disabled, so we need to add LightningCssMinimizerRspackPlugin to minify CSS files.
string | RegExp | Array<string | RegExp>
undefined
Specify the files to be minimized. You can use regular expressions or file path strings, and only the files that match will be minimized.
For example, the build generates /dist/foo.[hash].js
and some other JS files, we only minify foo.js
:
string | RegExp | Array<string | RegExp>
undefined
Same as test
, specify the files to be minimized.
string | RegExp | Array<string | RegExp>
undefined
Specify the files to be excluded. You can use regular expressions or file path strings, and the files that match will not be minimized.
For example, the build generates /dist/foo.[hash].js
and some other JS files, we exclude the minimization of foo.js
:
undefined
Whether comments shall be extracted to a separate file. If the original file is named foo.js
, then the comments will be stored to foo.js.LICENSE.txt
.
If value is true
, it is equivalent to /@preserve|@lic|@cc_on|^\**!/
regexp condition and remove remaining comments.
If value is false
, all comments will be removed.
If value is RegExp
, all comments that match the given expression will be extracted to the separate file.
If value is object
, it can use condition
and banner
to customize the extraction.
Similar to the jsc.minify
option of SWC, please refer to SWC - Minification for all available options.
For example, disable mangle
to avoid mangling variable names: