Skip to content

Commit

Permalink
feat: minifyJS options.output.comment 添加默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyuchen committed Nov 11, 2020
1 parent bb4d3f2 commit e967dac
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/plugin/minifyPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ function clearPool() {
}

function minifyJS(contents, options) {
const opts = JSON.parse(options);
const UglifyJS = require('uglify-js');
const result = UglifyJS.minify(contents, typeof opts === 'object' ? opts : undefined);
const UglifyJS = require('uglify-js');
if(options && options.output && options.output.comments) {
const comments = options.output.comments
if (comments !== 'all' && comments !== 'some' && typeof comments !== 'boolean') {
options.output.comments = /javascript-obfuscator:disable|javascript-obfuscator:enable/
}
}
const result = UglifyJS.minify(contents, typeof options === 'undefined' ? undefined : options);
if (result.error) {
console.error('[MinifyPlugin]', result.error);
throw result.error;
Expand Down Expand Up @@ -73,7 +78,7 @@ module.exports = class MinifyPlugin {
// asset.contents = result.code;
asset.contents = await pool.exec(minifyJS, [
asset.contents,
JSON.stringify(this.js)
this.js
]);
} else if (/\.json$/.test(asset.outputFilePath) && this.json) {
// asset.contents = jsonminify(asset.contents).toString();
Expand Down

0 comments on commit e967dac

Please sign in to comment.