简化(Minify simplify)

该插件主要通过两种方式转换代码 - 1) 尽可能多的将声明减少到表达式中 2) 使表达式尽可能一致,以获得更好的可压缩性

Example

Reduce statement into expression

In

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

Out

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

Make expression as uniform as possible for better compressibility

In

undefined
foo['bar']
Number(foo)

Out

void 0
foo.bar
+foo

Installation

npm install babel-plugin-minify-simplify

Usage

.babelrc

{
  "plugins": ["minify-simplify"]
}

Via CLI

babel --plugins minify-simplify script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["minify-simplify"]
});