Simplifies code for minification by reducing statements into expressions and making expressions uniform where possible.
In
function foo() {
if (x) a();
}
function foo2() {
if (x) a();
else b();
}
Out
function foo() {
x && a();
}
function foo2() {
x ? a() : b();
}
In
undefined
foo['bar']
Number(foo)
Out
void 0
foo.bar
+foo
npm install babel-plugin-minify-simplify --save-dev
.babelrc
{
"plugins": ["minify-simplify"]
}
babel --plugins minify-simplify script.js
require("@babel/core").transform("code", {
plugins: ["minify-simplify"]
});