mirror of
https://github.com/tauri-apps/tauri-inliner.git
synced 2026-02-04 02:31:19 +01:00
42 lines
973 B
JavaScript
42 lines
973 B
JavaScript
module.exports = uglify;
|
|
|
|
var debug = require('debug')('inliner');
|
|
var UglifyJS = require('uglify-js');
|
|
|
|
function uglify(source) {
|
|
var notIESafe = !this.options.iesafe;
|
|
|
|
this.emit('progress', 'compressing javascript');
|
|
|
|
source = source.trim();
|
|
|
|
if (source === '') {
|
|
this.jobs.done.js();
|
|
return '';
|
|
}
|
|
|
|
debug('uglifying %sbytes', source.length);
|
|
|
|
var result = '';
|
|
|
|
try {
|
|
result = UglifyJS.minify(source, {
|
|
fromString: true,
|
|
// must set screw_ie8 for each option group
|
|
// https://github.com/mishoo/UglifyJS2/issues/1204#issuecomment-234714094
|
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
|
compress: { screw_ie8: notIESafe },
|
|
mangle: { screw_ie8: notIESafe },
|
|
output: { screw_ie8: notIESafe },
|
|
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
|
|
}).code;
|
|
} catch (e) {
|
|
// failed to uglify, just return it plain
|
|
result = source;
|
|
}
|
|
|
|
this.jobs.done.js();
|
|
|
|
return result;
|
|
}
|