JoeR
JoeR

Reputation: 1911

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);

Upvotes: 7

Views: 1519

Answers (1)

dmnd
dmnd

Reputation: 2476

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

Upvotes: 1

Related Questions