Socket
Socket
Sign inDemoInstall

terser-webpack-plugin

Package Overview
Dependencies
295
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.1 to 2.0.0

26

CHANGELOG.md

@@ -5,2 +5,28 @@ # Changelog

## [2.0.0](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v1.4.1...v2.0.0) (2019-09-05)
### ⚠ BREAKING CHANGES
* minimum require Node.js version is `8.9.0`
* the `extractComments` option is `true` by default
* the `cache` option is `true` by default
* the `parallel` option is `true` by default
* using the `extractComments.condition` option with `true` value extract only `some` comments
### Bug Fixes
* do not run parallel mode when you have only one file ([#134](https://github.com/webpack-contrib/terser-webpack-plugin/issues/134)) ([8b88b39](https://github.com/webpack-contrib/terser-webpack-plugin/commit/8b88b39))
* make `extractComments` API more consistent ([#129](https://github.com/webpack-contrib/terser-webpack-plugin/issues/129)) ([37d2df0](https://github.com/webpack-contrib/terser-webpack-plugin/commit/37d2df0))
* parallel on wsl ([#138](https://github.com/webpack-contrib/terser-webpack-plugin/issues/138)) ([0537591](https://github.com/webpack-contrib/terser-webpack-plugin/commit/0537591))
### Features
* enable the cache option by default ([#132](https://github.com/webpack-contrib/terser-webpack-plugin/issues/132)) ([960d249](https://github.com/webpack-contrib/terser-webpack-plugin/commit/960d249))
* enable the extractComments option by default ([ad2471c](https://github.com/webpack-contrib/terser-webpack-plugin/commit/ad2471c))
* enable the parallel option by default ([#131](https://github.com/webpack-contrib/terser-webpack-plugin/issues/131)) ([7b342af](https://github.com/webpack-contrib/terser-webpack-plugin/commit/7b342af))
* respect `devtool` values for source map generation ([#140](https://github.com/webpack-contrib/terser-webpack-plugin/issues/140)) ([dd37ca1](https://github.com/webpack-contrib/terser-webpack-plugin/commit/dd37ca1))
### [1.4.1](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v1.4.0...v1.4.1) (2019-07-31)

@@ -7,0 +33,0 @@

202

dist/index.js

@@ -18,3 +18,3 @@ "use strict";

var _ModuleFilenameHelpers = _interopRequireDefault(require("webpack/lib/ModuleFilenameHelpers"));
var _webpack = require("webpack");

@@ -33,8 +33,2 @@ var _schemaUtils = _interopRequireDefault(require("schema-utils"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/;

@@ -44,3 +38,6 @@

constructor(options = {}) {
(0, _schemaUtils.default)(_options.default, options, 'Terser Plugin');
(0, _schemaUtils.default)(_options.default, options, {
name: 'Terser Plugin',
baseDataPath: 'options'
});
const {

@@ -52,7 +49,7 @@ minify,

warningsFilter = () => true,
extractComments = false,
sourceMap = false,
cache = false,
extractComments = true,
sourceMap,
cache = true,
cacheKeys = defaultCacheKeys => defaultCacheKeys,
parallel = false,
parallel = true,
include,

@@ -73,7 +70,8 @@ exclude

minify,
terserOptions: _objectSpread({
terserOptions: {
output: {
comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/i
}
}, terserOptions)
},
...terserOptions
}
};

@@ -96,20 +94,20 @@ }

static buildError(err, file, sourceMap, requestShortener) {
static buildError(error, file, sourceMap, requestShortener) {
// Handling error which should have line, col, filename and message
if (err.line) {
if (error.line) {
const original = sourceMap && sourceMap.originalPositionFor({
line: err.line,
column: err.col
line: error.line,
column: error.col
});
if (original && original.source && requestShortener) {
return new Error(`${file} from Terser\n${err.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${err.line},${err.col}]`);
return new Error(`${file} from Terser\n${error.message} [${requestShortener.shorten(original.source)}:${original.line},${original.column}][${file}:${error.line},${error.col}]`);
}
return new Error(`${file} from Terser\n${err.message} [${file}:${err.line},${err.col}]`);
} else if (err.stack) {
return new Error(`${file} from Terser\n${err.stack}`);
return new Error(`${file} from Terser\n${error.message} [${file}:${error.line},${error.col}]`);
} else if (error.stack) {
return new Error(`${file} from Terser\n${error.stack}`);
}
return new Error(`${file} from Terser\n${err.message}`);
return new Error(`${file} from Terser\n${error.message}`);
}

@@ -151,8 +149,11 @@

apply(compiler) {
this.options.sourceMap = typeof this.options.sourceMap === 'undefined' ? compiler.options.devtool && /^((inline|hidden|nosources)-)?source-?map/.test(compiler.options.devtool) : Boolean(this.options.sourceMap);
const buildModuleFn = moduleArg => {
// to get detailed location info about errors
// eslint-disable-next-line no-param-reassign
moduleArg.useSourceMap = true;
};
const optimizeFn = (compilation, chunks, callback) => {
const optimizeFn = async (compilation, chunks) => {
const taskRunner = new _TaskRunner.default({

@@ -167,3 +168,3 @@ cache: this.options.cache,

} = this.options;
Array.from(chunks).filter(chunk => chunkFilter && chunkFilter(chunk)).reduce((acc, chunk) => acc.concat(chunk.files || []), []).concat(compilation.additionalChunkAssets || []).filter(_ModuleFilenameHelpers.default.matchObject.bind(null, this.options)).forEach(file => {
Array.from(chunks).filter(chunk => chunkFilter && chunkFilter(chunk)).reduce((acc, chunk) => acc.concat(Array.from(chunk.files || [])), []).concat(Array.from(compilation.additionalChunkAssets || [])).filter(_webpack.ModuleFilenameHelpers.matchObject.bind(null, this.options)).forEach(file => {
let inputSourceMap;

@@ -235,98 +236,95 @@ const asset = compilation.assets[file];

});
taskRunner.run(tasks, (tasksError, results) => {
if (tasksError) {
compilation.errors.push(tasksError);
const completedTasks = await taskRunner.run(tasks);
await taskRunner.exit();
completedTasks.forEach((completedTask, index) => {
const {
file,
input,
inputSourceMap,
commentsFile
} = tasks[index];
const {
error,
map,
code,
warnings
} = completedTask;
let {
extractedComments
} = completedTask;
let sourceMap = null;
if (error || warnings && warnings.length > 0) {
sourceMap = TerserPlugin.buildSourceMap(inputSourceMap);
} // Handling results
// Error case: add errors, and go to next file
if (error) {
compilation.errors.push(TerserPlugin.buildError(error, file, sourceMap, new _RequestShortener.default(compiler.context)));
return;
}
results.forEach((data, index) => {
const {
file,
input,
inputSourceMap,
commentsFile
} = tasks[index];
const {
error,
map,
code,
warnings
} = data;
let {
extractedComments
} = data;
let sourceMap = null;
let outputSource;
if (error || warnings && warnings.length > 0) {
sourceMap = TerserPlugin.buildSourceMap(inputSourceMap);
} // Handling results
// Error case: add errors, and go to next file
if (map) {
outputSource = new _webpackSources.SourceMapSource(code, file, JSON.parse(map), input, inputSourceMap, true);
} else {
outputSource = new _webpackSources.RawSource(code);
} // Write extracted comments to commentsFile
if (error) {
compilation.errors.push(TerserPlugin.buildError(error, file, sourceMap, new _RequestShortener.default(compiler.context)));
return;
if (commentsFile && extractedComments && extractedComments.length > 0) {
if (commentsFile in compilation.assets) {
const commentsFileSource = compilation.assets[commentsFile].source();
extractedComments = extractedComments.filter(comment => !commentsFileSource.includes(comment));
}
let outputSource;
if (extractedComments.length > 0) {
// Add a banner to the original file
if (this.options.extractComments.banner !== false) {
let banner = this.options.extractComments.banner || `For license information please see ${_path.default.posix.basename(commentsFile)}`;
if (map) {
outputSource = new _webpackSources.SourceMapSource(code, file, JSON.parse(map), input, inputSourceMap, true);
} else {
outputSource = new _webpackSources.RawSource(code);
} // Write extracted comments to commentsFile
if (typeof banner === 'function') {
banner = banner(commentsFile);
}
if (commentsFile && extractedComments && extractedComments.length > 0) {
if (commentsFile in compilation.assets) {
const commentsFileSource = compilation.assets[commentsFile].source();
extractedComments = extractedComments.filter(comment => !commentsFileSource.includes(comment));
if (banner) {
outputSource = new _webpackSources.ConcatSource(`/*! ${banner} */\n`, outputSource);
}
}
if (extractedComments.length > 0) {
// Add a banner to the original file
if (this.options.extractComments.banner !== false) {
let banner = this.options.extractComments.banner || `For license information please see ${_path.default.posix.basename(commentsFile)}`;
const commentsSource = new _webpackSources.RawSource(`${extractedComments.join('\n\n')}\n`);
if (typeof banner === 'function') {
banner = banner(commentsFile);
}
if (banner) {
outputSource = new _webpackSources.ConcatSource(`/*! ${banner} */\n`, outputSource);
}
}
const commentsSource = new _webpackSources.RawSource(`${extractedComments.join('\n\n')}\n`);
if (commentsFile in compilation.assets) {
// commentsFile already exists, append new comments...
if (compilation.assets[commentsFile] instanceof _webpackSources.ConcatSource) {
compilation.assets[commentsFile].add('\n');
compilation.assets[commentsFile].add(commentsSource);
} else {
compilation.assets[commentsFile] = new _webpackSources.ConcatSource(compilation.assets[commentsFile], '\n', commentsSource);
}
if (commentsFile in compilation.assets) {
// commentsFile already exists, append new comments...
if (compilation.assets[commentsFile] instanceof _webpackSources.ConcatSource) {
compilation.assets[commentsFile].add('\n');
compilation.assets[commentsFile].add(commentsSource);
} else {
compilation.assets[commentsFile] = commentsSource;
// eslint-disable-next-line no-param-reassign
compilation.assets[commentsFile] = new _webpackSources.ConcatSource(compilation.assets[commentsFile], '\n', commentsSource);
}
} else {
// eslint-disable-next-line no-param-reassign
compilation.assets[commentsFile] = commentsSource;
}
} // Updating assets
}
} // Updating assets
// eslint-disable-next-line no-param-reassign
processedAssets.add(compilation.assets[file] = outputSource); // Handling warnings
processedAssets.add(compilation.assets[file] = outputSource); // Handling warnings
if (warnings && warnings.length > 0) {
warnings.forEach(warning => {
const builtWarning = TerserPlugin.buildWarning(warning, file, sourceMap, new _RequestShortener.default(compiler.context), this.options.warningsFilter);
if (warnings && warnings.length > 0) {
warnings.forEach(warning => {
const builtWarning = TerserPlugin.buildWarning(warning, file, sourceMap, new _RequestShortener.default(compiler.context), this.options.warningsFilter);
if (builtWarning) {
compilation.warnings.push(builtWarning);
}
});
}
});
taskRunner.exit();
callback();
if (builtWarning) {
compilation.warnings.push(builtWarning);
}
});
}
});
return Promise.resolve();
};

@@ -358,3 +356,3 @@

compilation.hooks.optimizeChunkAssets.tapAsync(plugin, optimizeFn.bind(this, compilation));
compilation.hooks.optimizeChunkAssets.tapPromise(plugin, optimizeFn.bind(this, compilation));
});

@@ -361,0 +359,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const {
minify: terserMinify
} = require('terser');
var _terser = require("terser");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const buildTerserOptions = ({

@@ -37,12 +28,16 @@ ecma,

warnings,
parse: _objectSpread({}, parse),
compress: typeof compress === 'boolean' ? compress : _objectSpread({}, compress),
parse: { ...parse
},
compress: typeof compress === 'boolean' ? compress : { ...compress
},
// eslint-disable-next-line no-nested-ternary
mangle: mangle == null ? true : typeof mangle === 'boolean' ? mangle : _objectSpread({}, mangle),
output: _objectSpread({
mangle: mangle == null ? true : typeof mangle === 'boolean' ? mangle : { ...mangle
},
output: {
shebang: true,
comments: false,
beautify: false,
semicolons: true
}, output),
semicolons: true,
...output
},
module,

@@ -59,2 +54,4 @@ // Ignoring sourceMap from options

const someCommentsRegExp = /^\**!|@preserve|@license|@cc_on/i;
const buildComments = (options, terserOptions, extractedComments) => {

@@ -66,3 +63,3 @@ const condition = {};

condition.preserve = commentsOpts;
condition.extract = /^\**!|@preserve|@license|@cc_on/i;
condition.extract = someCommentsRegExp;
} else if (typeof options.extractComments === 'string' || options.extractComments instanceof RegExp) {

@@ -78,3 +75,3 @@ // extractComments specifies the extract condition and commentsOpts specifies the preserve condition

condition.preserve = commentsOpts;
condition.extract = options.extractComments.condition;
condition.extract = typeof options.extractComments.condition === 'boolean' && options.extractComments.condition ? 'some' : options.extractComments.condition;
} else {

@@ -108,3 +105,3 @@ // No extract condition is given. Extract comments that match commentsOpts instead of preserving them

condition[key] = (astNode, comment) => {
return comment.type === 'comment2' && /^\**!|@preserve|@license|@cc_on/i.test(comment.value);
return comment.type === 'comment2' && someCommentsRegExp.test(comment.value);
};

@@ -178,3 +175,3 @@

warnings
} = (0, _terser.minify)({
} = terserMinify({
[file]: input

@@ -191,3 +188,2 @@ }, terserOptions);

var _default = minify;
exports.default = _default;
module.exports = minify;

@@ -14,8 +14,6 @@ "use strict";

var _workerFarm = _interopRequireDefault(require("worker-farm"));
var _jestWorker = _interopRequireDefault(require("jest-worker"));
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
var _isWsl = _interopRequireDefault(require("is-wsl"));
var _minify = _interopRequireDefault(require("./minify"));

@@ -25,100 +23,80 @@

const worker = require.resolve('./worker');
const workerPath = require.resolve('./worker');
class TaskRunner {
constructor(options = {}) {
const {
cache,
parallel
} = options;
this.cacheDir = cache === true ? (0, _findCacheDir.default)({
this.options = options;
this.cacheDir = TaskRunner.getCacheDirectory(this.options.cache);
this.numberWorkers = TaskRunner.getNumberWorkers(this.options.parallel);
}
static getCacheDirectory(cache) {
return cache === true ? (0, _findCacheDir.default)({
name: 'terser-webpack-plugin'
}) || _os.default.tmpdir() : cache; // In some cases cpus() returns undefined
}) || _os.default.tmpdir() : cache;
}
static getNumberWorkers(parallel) {
// In some cases cpus() returns undefined
// https://github.com/nodejs/node/issues/19022
const cpus = _os.default.cpus() || {
length: 1
}; // WSL sometimes freezes, error seems to be on the WSL side
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/21
this.maxConcurrentWorkers = _isWsl.default ? 1 : parallel === true ? cpus.length - 1 : Math.min(Number(parallel) || 0, cpus.length - 1);
};
return parallel === true ? cpus.length - 1 : Math.min(Number(parallel) || 0, cpus.length - 1);
}
run(tasks, callback) {
/* istanbul ignore if */
if (!tasks.length) {
callback(null, []);
return;
async runTask(task) {
if (this.worker) {
return this.worker.transform((0, _serializeJavascript.default)(task));
}
if (this.maxConcurrentWorkers > 1) {
const workerOptions = process.platform === 'win32' ? {
maxConcurrentWorkers: this.maxConcurrentWorkers,
maxConcurrentCallsPerWorker: 1
} : {
maxConcurrentWorkers: this.maxConcurrentWorkers
};
this.workers = (0, _workerFarm.default)(workerOptions, worker);
return (0, _minify.default)(task);
}
this.boundWorkers = (options, cb) => {
try {
this.workers((0, _serializeJavascript.default)(options), cb);
} catch (error) {
// worker-farm can fail with ENOMEM or something else
cb(error);
}
};
} else {
this.boundWorkers = (options, cb) => {
try {
cb(null, (0, _minify.default)(options));
} catch (error) {
cb(error);
}
};
async run(tasks) {
if (tasks.length === 0) {
return Promise.resolve([]);
}
let toRun = tasks.length;
const results = [];
if (this.numberWorkers > 1 && tasks.length > 1) {
this.worker = new _jestWorker.default(workerPath, {
numWorkers: this.numberWorkers
});
}
const step = (index, data) => {
toRun -= 1;
results[index] = data;
return Promise.all(tasks.map(task => {
const enqueue = async () => {
let result;
if (!toRun) {
callback(null, results);
}
};
tasks.forEach((task, index) => {
const enqueue = () => {
this.boundWorkers(task, (error, data) => {
const result = error ? {
try {
result = await this.runTask(task);
} catch (error) {
result = {
error
} : data;
};
}
const done = () => step(index, result);
if (this.cacheDir && !result.error) {
return _cacache.default.put(this.cacheDir, (0, _serializeJavascript.default)(task.cacheKeys), JSON.stringify(result)).then(() => result, () => result);
}
if (this.cacheDir && !result.error) {
_cacache.default.put(this.cacheDir, (0, _serializeJavascript.default)(task.cacheKeys), JSON.stringify(data)).then(done, done);
} else {
done();
}
});
return result;
};
if (this.cacheDir) {
_cacache.default.get(this.cacheDir, (0, _serializeJavascript.default)(task.cacheKeys)).then(({
return _cacache.default.get(this.cacheDir, (0, _serializeJavascript.default)(task.cacheKeys)).then(({
data
}) => step(index, JSON.parse(data)), enqueue);
} else {
enqueue();
}) => JSON.parse(data), enqueue);
}
});
return enqueue();
}));
}
exit() {
if (this.workers) {
_workerFarm.default.end(this.workers);
async exit() {
if (!this.worker) {
return Promise.resolve();
}
return this.worker.end();
}

@@ -125,0 +103,0 @@

"use strict";
var _minify = _interopRequireDefault(require("./minify"));
const minify = require('./minify');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function transform(options) {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
// eslint-disable-next-line no-new-func, no-param-reassign
options = new Function('exports', 'require', 'module', '__filename', '__dirname', `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
const result = minify(options);
module.exports = (options, callback) => {
try {
// 'use strict' => this === undefined (Clean Scope)
// Safer for possible security issues, albeit not critical at all here
// eslint-disable-next-line no-new-func, no-param-reassign
options = new Function('exports', 'require', 'module', '__filename', '__dirname', `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
callback(null, (0, _minify.default)(options));
} catch (errors) {
callback(errors);
if (result.error) {
throw result.error;
} else {
return result;
}
};
}
module.exports.transform = transform;
{
"name": "terser-webpack-plugin",
"version": "1.4.1",
"version": "2.0.0",
"description": "Terser plugin for webpack",

@@ -12,3 +12,3 @@ "license": "MIT",

"engines": {
"node": ">= 6.9.0"
"node": ">= 8.9.0"
},

@@ -41,11 +41,10 @@ "scripts": {

"dependencies": {
"cacache": "^12.0.2",
"find-cache-dir": "^2.1.0",
"is-wsl": "^1.1.0",
"schema-utils": "^1.0.0",
"serialize-javascript": "^1.7.0",
"cacache": "^12.0.3",
"find-cache-dir": "^3.0.0",
"jest-worker": "^24.9.0",
"schema-utils": "^2.2.0",
"serialize-javascript": "^2.1.0",
"source-map": "^0.6.1",
"terser": "^4.1.2",
"webpack-sources": "^1.4.0",
"worker-farm": "^1.7.0"
"terser": "^4.2.1",
"webpack-sources": "^1.4.3"
},

@@ -60,14 +59,14 @@ "devDependencies": {

"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^24.8.0",
"babel-jest": "^24.9.0",
"commitlint-azure-pipelines-cli": "^1.0.2",
"cross-env": "^5.2.0",
"del": "^4.1.1",
"del-cli": "^1.1.0",
"eslint": "^6.1.0",
"eslint-config-prettier": "^6.0.0",
"cross-env": "^5.2.1",
"del": "^5.1.0",
"del-cli": "^2.0.0",
"eslint": "^6.3.0",
"eslint-config-prettier": "^6.2.0",
"eslint-plugin-import": "^2.18.2",
"husky": "^3.0.2",
"jest": "^24.8.0",
"jest-junit": "^7.0.0",
"lint-staged": "^9.2.1",
"husky": "^3.0.5",
"jest": "^24.9.0",
"jest-junit": "^8.0.0",
"lint-staged": "^9.2.5",
"memory-fs": "^0.4.1",

@@ -78,3 +77,3 @@ "npm-run-all": "^4.1.5",

"uglify-js": "^3.6.0",
"webpack": "^4.38.0"
"webpack": "^4.39.3"
},

@@ -81,0 +80,0 @@ "keywords": [

@@ -19,4 +19,2 @@ <div align="center">

> ℹ️ For `webpack@3` use [terser-webpack-plugin-legacy](https://www.npmjs.com/package/terser-webpack-plugin-legacy) package
## Getting Started

@@ -39,2 +37,3 @@

optimization: {
minimize: true,
minimizer: [new TerserPlugin()],

@@ -61,2 +60,3 @@ },

optimization: {
minimize: true,
minimizer: [

@@ -83,2 +83,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -105,2 +106,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -128,2 +130,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -148,3 +151,3 @@ new TerserPlugin({

Type: `Boolean|String`
Default: `false`
Default: `true`

@@ -165,2 +168,3 @@ Enable file caching.

optimization: {
minimize: true,
minimizer: [

@@ -184,2 +188,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -221,2 +226,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -239,3 +245,3 @@ new TerserPlugin({

Type: `Boolean|Number`
Default: `false`
Default: `true`

@@ -256,2 +262,3 @@ Use multi-process parallel running to improve the build speed.

optimization: {
minimize: true,
minimizer: [

@@ -275,2 +282,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -290,7 +298,15 @@ new TerserPlugin({

**Works only with `source-map`, `inline-source-map`, `hidden-source-map` and `nosources-source-map` values for the [`devtool`](https://webpack.js.org/configuration/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`](https://webpack.js.org/configuration/devtool/).
Using supported `devtool` values enable 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.
> ⚠️ **`cheap-source-map` options don't work with this plugin**.
**webpack.config.js**

@@ -301,2 +317,3 @@

optimization: {
minimize: true,
minimizer: [

@@ -327,2 +344,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -360,2 +378,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -403,2 +422,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -422,2 +442,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -441,2 +462,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -460,2 +482,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -485,2 +508,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -514,2 +538,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -545,2 +570,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -575,2 +601,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -606,2 +633,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -628,21 +656,2 @@ new TerserPlugin({

### Cache And Parallel
Enable cache and multi-process parallel running.
**webpack.config.js**
```js
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
}),
],
},
};
```
### Preserve Comments

@@ -657,2 +666,3 @@

optimization: {
minimize: true,
minimizer: [

@@ -681,2 +691,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -704,2 +715,3 @@ new TerserPlugin({

optimization: {
minimize: true,
minimizer: [

@@ -706,0 +718,0 @@ new TerserPlugin({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc