UNPKG

parcel-bundler

Version:

<p align="center"> <a href="https://parceljs.org/" target="_blank"> <img alt="Parcel" src="https://user-images.githubusercontent.com/19409/31321658-f6aed0f2-ac3d-11e7-8100-1587e676e0ec.png" width="749"> </a> </p>

43 lines (35 loc) 915 B
const {minify} = require('uglify-es'); const config = require('../utils/config'); module.exports = async function(asset) { await asset.parseIfNeeded(); // Convert AST into JS let code = asset.generate().js; let customConfig = await config.load(asset.name, ['.uglifyrc']); let options = { warnings: true, mangle: { toplevel: true }, compress: { drop_console: true } }; if (customConfig) { options = Object.assign(options, customConfig); } let result = minify(code, options); if (result.error) { throw result.error; } // Log all warnings if (result.warnings) { result.warnings.forEach(warning => { // TODO: warn this using the logger console.log(warning); }); } // babel-generator did our code generation for us, so remove the old AST asset.ast = null; asset.outputCode = result.code; asset.isAstDirty = false; };