How to use the minification.deadCodeElimination transformer.
Remove dead code.
require("babel").transform("code", { optional: ["minification.deadCodeElimination"] });
$ babel --optional minification.deadCodeElimination script.js
In
if (true) {
foo();
} else {
bar();
}
Out
foo();
In
if (false) {
foo();
} else {
bar();
}
Out
bar();
In
if (foo) {
} else {
bar();
}
Out
if (!foo) {
bar();
}
In
if (foo) {
bar();
} else {
}
Out
if (foo) {
bar();
}
In
true ? foo : bar
Out
foo
In
false ? foo : bar
Out
bar
In
class Foo {}
class Bar {}
new Foo;
Out
class Foo {}
new Foo;
In
function foo() {}
function bar() {}
foo();
Out
function foo() {}
foo();
In
var foo = "bar";
bar(foo);
Out
bar("bar");