-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
47 lines (40 loc) · 1.17 KB
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const uglify = require("uglify-js");
module.exports = (input, file, options, cb) => {
let stream;
if (!/\.js($|\?)/.test(file)) return;
try {
stream = minimizeJs(input, file, options);
} catch(err) {
return cb(err);
}
cb(null, stream);
};
function minimizeJs(input, file, options) {
uglify.base54.reset();
let ast = uglify.parse(input, {
filename: file,
});
ast.figure_out_scope();
const compress = uglify.Compressor(options.compress || {
warnings: false
});
ast = ast.transform(compress);
ast.figure_out_scope(options.mangle || {});
ast.compute_char_frequency(options.mangle || {});
ast.mangle_names(options.mangle || {});
if(options.mangle && options.mangle.props) {
uglify.mangle_properties(ast, options.mangle.props);
}
let output = {};
output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
output.beautify = options.beautify;
output['ascii_only'] = true;
for (let k in options.output) {
output[k] = options.output[k];
}
let stream = uglify.OutputStream(output);
ast.print(stream);
stream = stream + "";
return stream;
}