我编写了一个简单的bash脚本,使用mishoo/UglifyJS2和这行代码自动缩小一些存储库:
../bower_components/UglifyJS2/bin/uglifyjs src/* -c -m -o ${minifiedFile}
它在我的 Mac 上运行良好,但我的同事无法运行它并出现以下错误:
C:\Users\User\uabshp\bower_components\UglifyJS2\bin\uglifyjs:111
.array("reserved-file")
^
TypeError: yargs.usage(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).describe(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).alias(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).string(...).array is not a function
at Object.<anonymous> (C:\Users\User\uabshp\bower_components\UglifyJS2\bin\uglifyjs:111:6)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:352:7)
at startup (bootstrap_node.js:144:9)
at bootstrap_node.js:467:3
这是 Windows 兼容性问题还是设置中缺少某些内容?我已经不得不从 compressJs 切换到尝试让 minify 在 Windows 上工作。
最佳答案
这不是一个完美的解决方案,但它对我有用。我删除了 UglifyJS2/bin/uglifyjs.js
中给我带来麻烦的行。
第 72 行:
.describe("reserved-file", "File containing reserved names")
第 77 行:
.describe("pure-funcs", "List of functions that can be safely removed if their return value is not used")
。 第 111-112 行:
.array("reserved-file")
.array("pure-funcs")
行号 536-554:
ast.walk(new UglifyJS.TreeWalker(function(node){
if (node instanceof UglifyJS.AST_Seq) return; // descend
if (node instanceof UglifyJS.AST_Assign) {
var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_");
var value = node.right;
if (constants)
value = new Function("return (" + value.print_to_string() + ")")();
ret[name] = value;
return true; // no descend
}
if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_Binary) {
var name = node.print_to_string({ beautify: false }).replace(/-/g, "_");
ret[name] = true;
return true; // no descend
}
print_error(node.TYPE)
print_error("Error parsing arguments for flag `" + flag + "': " + x);
process.exit(1);
}));
删除的行显然会影响功能,但它仍然适用于我的目的。如果有人有更好的解决方案,我会标记它。
关于javascript - UglifyJS2 在 .array ("reserved-file"上抛出 TypeError ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485463/