Skip to content

Commit

Permalink
fix #26: 当调用UglifyJS.minify时,只把uglify-js需要的参数传进去,避免传入无用参数引起uglify-js报错。
Browse files Browse the repository at this point in the history
这一fix版本使用了ES6语法,因而可能无法支持老版本Node。
  • Loading branch information
Starrah committed Feb 27, 2022
1 parent f558657 commit c857fa7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ function logic_js(str, data) {
}
}

var result = UglifyJS.minify(str, options);
const uglify_v3_allow_options = ["parse", "compress", "mangle", "output", "sourceMap", "nameCache", "toplevel", "warnings"]
const uglify_options = {}
for (let key of uglify_v3_allow_options) {
if (options[key] !== undefined) uglify_options[key] = options[key]
}

var result = UglifyJS.minify(str, uglify_options);
if (!result.error) {
var saved = (((str.length - result.code.length) / str.length) * 100).toFixed(2);
if (options.logger) {
Expand All @@ -91,7 +97,7 @@ function logic_js(str, data) {
var prefix = '// build time:' + Date().toLocaleString() + '\n';
var end = '\n//rebuild by neat ';
js_result = prefix + result.code + end;
}
} else throw result.error;
return js_result;
}

Expand Down

0 comments on commit c857fa7

Please sign in to comment.