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
- Yarn
- pnpm
npm install babel-plugin-minify-simplify --save-dev
yarn add babel-plugin-minify-simplify --dev
pnpm add babel-plugin-minify-simplify --save-dev
Usage
With a configuration file (Recommended)
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"]
});