跳到主要内容

babel-plugin-minify-simplify

Example

Reduce statement into expression

In

JavaScript
function foo() {
if (x) a();
}
function foo2() {
if (x) a();
else b();
}

Out

JavaScript
function foo() {
x && a();
}
function foo2() {
x ? a() : b();
}

Make expression as uniform as possible for better compressibility

In

JavaScript
undefined
foo['bar']
Number(foo)

Out

JavaScript
void 0
foo.bar
+foo

Installation

npm install babel-plugin-minify-simplify --save-dev

Usage

babel.config.json
{
"plugins": ["minify-simplify"]
}

Via CLI

Shell
babel --plugins minify-simplify script.js

Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["minify-simplify"]
});