terser-webpack-plugin
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [2.1.1](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v2.1.0...v2.1.1) (2019-09-27) | ||
### Bug Fixes | ||
* logic for extracting and preserving comments ([#166](https://github.com/webpack-contrib/terser-webpack-plugin/issues/166)) ([6bdee64](https://github.com/webpack-contrib/terser-webpack-plugin/commit/6bdee64)) | ||
## [2.1.0](https://github.com/webpack-contrib/terser-webpack-plugin/compare/v2.0.1...v2.1.0) (2019-09-16) | ||
@@ -7,0 +14,0 @@ |
@@ -66,8 +66,3 @@ "use strict"; | ||
minify, | ||
terserOptions: { | ||
output: { | ||
comments: extractComments ? false : /^\**!|@preserve|@license|@cc_on/i | ||
}, | ||
...terserOptions | ||
} | ||
terserOptions | ||
}; | ||
@@ -74,0 +69,0 @@ } |
@@ -36,6 +36,3 @@ "use strict"; | ||
output: { | ||
shebang: true, | ||
comments: false, | ||
beautify: false, | ||
semicolons: true, | ||
...output | ||
@@ -54,26 +51,29 @@ }, | ||
const someCommentsRegExp = /^\**!|@preserve|@license|@cc_on/i; | ||
function isObject(value) { | ||
const type = typeof value; | ||
return value != null && (type === 'object' || type === 'function'); | ||
} | ||
const buildComments = (options, terserOptions, extractedComments) => { | ||
const condition = {}; | ||
const commentsOpts = terserOptions.output.comments; // Use /^\**!|@preserve|@license|@cc_on/i RegExp | ||
const commentsOpts = terserOptions.output.comments; | ||
const { | ||
extractComments | ||
} = options; | ||
condition.preserve = typeof commentsOpts !== 'undefined' ? commentsOpts : false; | ||
if (typeof options.extractComments === 'boolean') { | ||
condition.preserve = commentsOpts; | ||
condition.extract = someCommentsRegExp; | ||
} else if (typeof options.extractComments === 'string' || options.extractComments instanceof RegExp) { | ||
// extractComments specifies the extract condition and commentsOpts specifies the preserve condition | ||
condition.preserve = commentsOpts; | ||
condition.extract = options.extractComments; | ||
} else if (typeof options.extractComments === 'function') { | ||
condition.preserve = commentsOpts; | ||
condition.extract = options.extractComments; | ||
} else if (Object.prototype.hasOwnProperty.call(options.extractComments, 'condition')) { | ||
// Extract condition is given in extractComments.condition | ||
condition.preserve = commentsOpts; | ||
condition.extract = typeof options.extractComments.condition === 'boolean' && options.extractComments.condition ? 'some' : options.extractComments.condition; | ||
if (typeof extractComments === 'boolean' && extractComments) { | ||
condition.extract = 'some'; | ||
} else if (typeof extractComments === 'string' || extractComments instanceof RegExp) { | ||
condition.extract = extractComments; | ||
} else if (typeof extractComments === 'function') { | ||
condition.extract = extractComments; | ||
} else if (isObject(extractComments)) { | ||
condition.extract = typeof extractComments.condition === 'boolean' && extractComments.condition ? 'some' : typeof extractComments.condition !== 'undefined' ? extractComments.condition : 'some'; | ||
} else { | ||
// No extract condition is given. Extract comments that match commentsOpts instead of preserving them | ||
condition.preserve = false; | ||
condition.extract = commentsOpts; | ||
// No extract | ||
// Preserve using "commentsOpts" or "some" | ||
// Todo remove this in next major release | ||
condition.preserve = typeof commentsOpts !== 'undefined' ? commentsOpts : 'some'; | ||
condition.extract = false; | ||
} // Ensure that both conditions are functions | ||
@@ -103,3 +103,3 @@ | ||
condition[key] = (astNode, comment) => { | ||
return comment.type === 'comment2' && someCommentsRegExp.test(comment.value); | ||
return comment.type === 'comment2' && /^\**!|@preserve|@license|@cc_on/i.test(comment.value); | ||
}; | ||
@@ -145,3 +145,2 @@ | ||
inputSourceMap, | ||
extractComments, | ||
minify: minifyFn | ||
@@ -164,7 +163,3 @@ } = options; | ||
const extractedComments = []; | ||
if (extractComments) { | ||
terserOptions.output.comments = buildComments(options, terserOptions, extractedComments); | ||
} | ||
terserOptions.output.comments = buildComments(options, terserOptions, extractedComments); | ||
const { | ||
@@ -171,0 +166,0 @@ error, |
{ | ||
"name": "terser-webpack-plugin", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Terser plugin for webpack", | ||
@@ -40,9 +40,9 @@ "license": "MIT", | ||
"dependencies": { | ||
"cacache": "^12.0.3", | ||
"cacache": "^13.0.0", | ||
"find-cache-dir": "^3.0.0", | ||
"jest-worker": "^24.9.0", | ||
"schema-utils": "^2.2.0", | ||
"schema-utils": "^2.4.1", | ||
"serialize-javascript": "^2.1.0", | ||
"source-map": "^0.6.1", | ||
"terser": "^4.3.1", | ||
"terser": "^4.3.3", | ||
"webpack-sources": "^1.4.3" | ||
@@ -60,3 +60,3 @@ }, | ||
"commitlint-azure-pipelines-cli": "^1.0.2", | ||
"cross-env": "^5.2.1", | ||
"cross-env": "^6.0.0", | ||
"del": "^5.1.0", | ||
@@ -70,3 +70,3 @@ "del-cli": "^3.0.0", | ||
"jest-junit": "^8.0.0", | ||
"lint-staged": "^9.2.5", | ||
"lint-staged": "^9.4.0", | ||
"memory-fs": "^0.4.1", | ||
@@ -73,0 +73,0 @@ "npm-run-all": "^4.1.5", |
@@ -665,3 +665,3 @@ <div align="center"> | ||
If you avoid building with comments, set **terserOptions.output.comments** to **false** as in this config: | ||
If you avoid building with comments, use this config: | ||
@@ -681,2 +681,3 @@ **webpack.config.js** | ||
}, | ||
extractComments: false, | ||
}), | ||
@@ -683,0 +684,0 @@ ], |
754
53806
723
+ Addedaggregate-error@3.1.0(transitive)
+ Addedcacache@13.0.1(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedminipass@3.3.6(transitive)
+ Addedminipass-collect@1.0.2(transitive)
+ Addedminipass-flush@1.0.5(transitive)
+ Addedminipass-pipeline@1.2.4(transitive)
+ Addedp-map@3.0.0(transitive)
+ Addedssri@7.1.1(transitive)
+ Addedyallist@4.0.0(transitive)
Updatedcacache@^13.0.0
Updatedschema-utils@^2.4.1
Updatedterser@^4.3.3