For instance, I have the following code:
if ("a" !== "a") {
console.log('really?');
}
var a = 5;
Then I write uglifyjs code.js -o code.min.js
. As a result, I have the following:
if("a"!=="a"){console.log("really?")}var a=5;
How do I enable removing the dead code inside the if-statement?
Despite this question has already got an accepted answer, I think it's worth mentioning that
UglifyJS2
does remove dead code
To turn this feature on, you need to set appropriate option either in CLI (uglifyjs --compress unused,dead_code
) or in the options
object if you invoke uglify
programmatically (uglify(compress: { unused: true, dead_code: true });
).