有没有办法在 Node 脚本中调用 UglifyJS2 API(即通过调用 require('uglify-js').minify
)对一串代码,以便它删除死/无法访问的代码但不应用任何压缩
例如:
var foo = 'bar';
if (false) {
foo = 'yo';
}
alert('Foo value found');
alert(foo);
会成为
var foo = 'bar';
alert('Foo value found');
alert(foo);
最佳答案
答案很晚,但是 compress: {defaults: false, dead_code: true, unused: true}
将在 Terser 中工作。 See docs .
关于node.js - 仅删除死代码的 UglifyJS 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34361272/