79 lines
No EOL
1.9 KiB
JavaScript
79 lines
No EOL
1.9 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
|
|
const _require = require('terser'),
|
|
minify = _require.minify;
|
|
|
|
const SourceMap = require('../SourceMap');
|
|
|
|
module.exports =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ref = (0, _asyncToGenerator2.default)(function* (asset) {
|
|
yield asset.parseIfNeeded(); // Convert AST into JS
|
|
|
|
let source = (yield asset.generate())[0].value;
|
|
let customConfig = yield asset.getConfig(['.uglifyrc', '.terserrc']);
|
|
let options = {
|
|
warnings: true,
|
|
safari10: true,
|
|
mangle: {
|
|
toplevel: !asset.options.scopeHoist
|
|
}
|
|
};
|
|
let sourceMap;
|
|
|
|
if (asset.options.sourceMaps) {
|
|
sourceMap = new SourceMap();
|
|
options.output = {
|
|
source_map: {
|
|
add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
|
sourceMap.addMapping({
|
|
source,
|
|
name,
|
|
original: {
|
|
line: orig_line,
|
|
column: orig_col
|
|
},
|
|
generated: {
|
|
line: gen_line,
|
|
column: gen_col
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
};
|
|
}
|
|
|
|
if (customConfig) {
|
|
options = Object.assign(options, customConfig);
|
|
}
|
|
|
|
let result = minify(source, options);
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
|
|
if (sourceMap) {
|
|
if (asset.sourceMap) {
|
|
asset.sourceMap = yield new SourceMap().extendSourceMap(asset.sourceMap, sourceMap);
|
|
} else {
|
|
asset.sourceMap = sourceMap;
|
|
}
|
|
} // babel-generator did our code generation for us, so remove the old AST
|
|
|
|
|
|
asset.ast = null;
|
|
asset.outputCode = result.code;
|
|
asset.isAstDirty = false;
|
|
});
|
|
|
|
return function (_x) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}(); |