babel-plugin-minify-simplify

Example

Reduce statement into expression

In

  1. function foo() {
  2. if (x) a();
  3. }
  4. function foo2() {
  5. if (x) a();
  6. else b();
  7. }

Out

  1. function foo() {
  2. x && a();
  3. }
  4. function foo2() {
  5. x ? a() : b();
  6. }

Make expression as uniform as possible for better compressibility

In

  1. undefined
  2. foo['bar']
  3. Number(foo)

Out

  1. void 0
  2. foo.bar
  3. +foo

Installation

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

Usage

.babelrc

  1. {
  2. "plugins": ["minify-simplify"]
  3. }

Via CLI

  1. babel --plugins minify-simplify script.js

Via Node API

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