node.jsuglifyjs2

UglifyJS options to only remove dead code


Is there a way to call the UglifyJS2 API in a node script (ie by calling require('uglify-js').minify) on a string of code such that it removes dead/unreachable code but does not apply any compression

For example:

var foo = 'bar';
if (false) {
    foo = 'yo';
}
alert('Foo value found');
alert(foo);

Would become

var foo = 'bar';
alert('Foo value found');
alert(foo);

Solution

  • Very late answer, but compress: {defaults: false, dead_code: true, unused: true} will work in Terser. See docs.