Use multi-process parallel running to improve the build speed. Default number of concurrent runs: os.cpus().length - 1.
ℹ️ Parallelization can speedup your build significantly and is therefore highly recommended.
⚠️ If you use Circle CI or any other environment that doesn't provide real available count of CPUs then you need to setup explicitly number of CPUs to avoid Error: Call retries were exceeded (see #143, #202).
Type: Boolean Default: false (see below for details around devtool value and SourceMapDevToolPlugin plugin)
Works only with source-map, inline-source-map, hidden-source-map and nosources-source-map values for the devtool option.
Why?
eval wraps modules in eval("string") and the minimizer does not handle strings.
cheap has not column information and minimizer generate only a single line, which leave only a single mapping.
The plugin respect the devtool and using the SourceMapDevToolPlugin plugin. Using supported devtool values enable source map generation. Using SourceMapDevToolPlugin with enabled the columns option enables source map generation.
Use source maps to map error message locations to modules (this slows down the compilation). If you use your own minify function please read the minify section for handling source maps correctly.
Whether comments shall be extracted to a separate file, (see details). By default extract only comments using /^\**!|@preserve|@license|@cc_on/i regexp condition and remove remaining comments. If the original file is named foo.js, then the comments will be stored to foo.js.LICENSE.txt. The terserOptions.output.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 preserving comments that have been extracted.
Allow to customize condition for extract comments, specify extracted file name and banner.
webpack.config.js
module.exports= { optimization: { minimize:true, minimizer: [newTerserPlugin({ extractComments: { condition: /^\**!|@preserve|@license|@cc_on/i,filename: (file, fileData) => {// ⚠ webpack 5: there is only fileData parameter// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)// You must consider this// The "fileData" argument contains object with "filename", "basename", "query"returnfile.replace(/\.(\w+)($|\?)/,'.$1.LICENSE.txt$2'); },banner: (licenseFile) => {return`License information can be found in ${licenseFile}`; }, }, }), ], },};
module.exports= { optimization: { minimize:true, minimizer: [newTerserPlugin({ extractComments: { condition:'some',filename: (file, fileData) => {// ⚠ webpack 5: there is only fileData parameter// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)// You must consider thisreturnfile.replace(/\.(\w+)($|\?)/,'.$1.LICENSE.txt$2'); },banner: (licenseFile) => {return`License information can be found in ${licenseFile}`; }, }, }), ], },};
Available placeholders: [file], [query] and [filebase] ([base] for webpack 5).
The file where the extracted comments will be stored. Default is to append the suffix .LICENSE.txt to the original filename.
webpack.config.js
module.exports= { optimization: { minimize:true, minimizer: [newTerserPlugin({ extractComments: { condition: /^\**!|@preserve|@license|@cc_on/i, filename:'extracted-comments.js',banner: (licenseFile) => {return`License information can be found in ${licenseFile}`; }, }, }), ], },};
banner
Type: Boolean|String|Function<(string) -> String> Default: /*! For license information please see ${commentsFile} */
The banner text that points to the extracted file and will be added on top of the original file. Can be false (no banner), a String, or a Function<(string) -> String> that will be called with the filename where extracted comments have been stored. Will be wrapped into comment.
webpack.config.js
module.exports= { optimization: { minimize:true, minimizer: [newTerserPlugin({ extractComments: { condition:true,filename: (file, fileData) => {// ⚠ webpack 5: there is only fileData parameter// A file can contain a query string (for example when you have `output.filename: '[name].js?[chunkhash]'`)// You must consider thisreturnfile.replace(/\.(\w+)($|\?)/,'.$1.LICENSE.txt$2'); },banner: (commentsFile) => {return`My custom banner about license information ${commentsFile}`; }, }, }), ], },};