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);
if (false)block will never be evaluated so it can be removed. Closure compiler etc does this and it's a feature of UglifyJS2. The use for this is pretty niche but to elaborate it's a build script which takes a source which is out of my control and does some modifications which renders some parts of the script 'dead'. These parts need to be removed because they interfere with another part of the build process. As I said - niche use case where I know it to be a safe/necessary operation.compress: { dead_code: true, unused: true }inoptions