updating the minifier-js to modernize it's syntax and review and update it configuration. The configuration options and settings are also documented as to why and how they are being set so future developers will understand why it is configured as it is

This commit is contained in:
Brian Mulhall
2020-03-14 12:42:20 -05:00
parent 783a9c7ecb
commit cc4b6d81fe

View File

@@ -1,17 +1,17 @@
var terser;
const terser = Npm.require("terser");
meteorJsMinify = function (source) {
var result = {};
var NODE_ENV = process.env.NODE_ENV || "development";
terser = terser || Npm.require("terser");
const result = {};
const NODE_ENV = process.env.NODE_ENV || "development";
try {
var terserResult = terser.minify(source, {
const options = {
compress: {
drop_debugger: false,
unused: false,
dead_code: true,
passes: 1, // default is 1 (2 or more passes could lead to better compression)
inline: true, // default is true which will aggresively inline functions
drop_debugger: false, // remove debugger; statements
unused: false, // drop unreferenced functions and variables
dead_code: true, // remove unreachable code
global_defs: {
"process.env.NODE_ENV": NODE_ENV
}
@@ -19,24 +19,26 @@ meteorJsMinify = function (source) {
// Fix issue #9866, as explained in this comment:
// https://github.com/mishoo/UglifyJS2/issues/1753#issuecomment-324814782
// And fix terser issue #117: https://github.com/terser-js/terser/issues/117
safari10: true,
});
safari10: true, // set this option to true to work around the Safari 10/11 await bug
};
const terserResult = terser.minify(source, options);
if (typeof terserResult.code === "string") {
result.code = terserResult.code;
result.minifier = 'terser';
} else {
throw terserResult.error ||
new Error("unknown terser.minify failure");
throw terserResult.error || new Error("unknown terser.minify failure");
}
} catch (e) {
} catch (err) {
// Although Babel.minify can handle a wider variety of ECMAScript
// 2015+ syntax, it is substantially slower than UglifyJS/terser, so
// 2015+ syntax, it is substantially slower than terser, so
// we use it only as a fallback.
var options = Babel.getMinifierOptions({
const options = Babel.getMinifierOptions({
inlineNodeEnv: NODE_ENV
});
result.code = Babel.minify(source, options).code;
result.minifier = 'babel-minify';
}