✂️ An ES6+ aware minifier based on the Babel toolchain (beta)
Switch branches/tags
Clone or download
Stephanemw and boopathi chore(minify): remediate CVE-2018-3721: update lodash to latest, remo…
…ve use of deprecated module packages (#918)

* chore(minify): update lodash to latest, remove use of deprecated modularised lodash packages

* chore(minify): update lodash to latest, remove use of deprecated modularised lodash packages
Latest commit 245949f Oct 29, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github chore: Update babel to 7.0.0-beta.49 (#872) Jun 11, 2018
docs add lint-staged - lint and test Jan 20, 2018
packages chore(minify): remediate CVE-2018-3721: update lodash to latest, remo… Oct 29, 2018
scripts style: fix lint Sep 24, 2018
smoke chore: upgrade dependencies; add node 10; remove node 9 (#827) May 1, 2018
utils Publish Sep 24, 2018
.editorconfig Add editorconfig (#63) Jul 30, 2016
.eslintignore Fix lint issues Nov 8, 2017
.eslintrc.js chore(eslint): mark as root config Feb 26, 2018
.gitattributes Specify *.jar as binary in gitattributes (#714) Nov 7, 2017
.gitignore ignore tmp files (*~$) Nov 9, 2017
.gitmodules Remove draft-js from smoktests dir (#648) Aug 8, 2017
.prettierignore feat(bench): add terser. remove butternut (#883) Jul 17, 2018
.travis.yml chore: Don't do shallow clones on travis (#907) Sep 29, 2018
.yarnrc Add yarnrc for Travis yarn@0.27.5 Sep 18, 2017
CHANGELOG.md chore: update changelog for 0.5.0 Sep 24, 2018
CODE_OF_CONDUCT.md Update CodeOfConduct to Contributor Covenant 1.4 [skip ci] (#737) Dec 11, 2017
CONTRIBUTING.md add friendly introduction to contributing.md from https://github.com/… May 14, 2018
LICENSE Add license (#98) Aug 26, 2016
NPM_OWNERS npm owners scripts Oct 24, 2016
README.md chore: update Requirements section in README.md (#910) Oct 1, 2018
appveyor.yml chore: travis- remove submodule, appveyor- upgrade yarn Jun 1, 2018
babel.config.js chore: upgrade dependencies; add node 10; remove node 9 (#827) May 1, 2018
circle.yml Update CI yml files (#716) Nov 7, 2017
codecov.yml revert ci tweaks Jan 19, 2018
gulpfile.js feat: upgrade to babel-7 Feb 15, 2018
lerna.json Upgrade to babel@7 and lerna@3 (#900) Sep 20, 2018
package.json chore: upgrade dependencies; fix tests Sep 24, 2018
yarn.lock chore(minify): remediate CVE-2018-3721: update lodash to latest, remo… Oct 29, 2018

README.md

babel-minify

An ES6+ aware minifier based on the Babel toolchain.

NPM Version Travis Status CircleCI Status AppveyorCI Status Code Coverage Slack Status NPM Downloads

Note

Babili has been now renamed to Babel-Minify :).

Table of Contents

Requirements

  • node >= 6
  • babel >= 6.20.0

Why

Current tools don't support targeting the latest version of ECMAScript. (yet)

  • BabelMinify can because it is just a set of Babel plugins, and Babel already understands new syntax with our parser Babylon.
  • When it's possible to only target browsers that support newer ES features, code sizes can be smaller because you don't have to transpile and then minify.

Check out our blog post for more info!

// Example ES2015 Code
class Mangler {
  constructor(program) {
    this.program = program;
  }
}
new Mangler(); // without this it would just output nothing since Mangler isn't used

Before

// ES2015+ code -> Babel -> BabelMinify/Uglify -> Minified ES5 Code
var a=function a(b){_classCallCheck(this,a),this.program=b};new a;

After

// ES2015+ code -> BabelMinify -> Minified ES2015+ Code
class a{constructor(b){this.program=b}}new a;

CLI

Package Version Dependencies
babel-minify npm Dependency Status

Install

npm install babel-minify --save-dev

Usage

minify src -d lib

Babel preset

Package Version Dependencies
babel-preset-minify npm Dependency Status

Install

npm install babel-preset-minify --save-dev

Usage

You'll most likely want to use it only in the production environment. Check out the env docs for more help.

Options specific to a certain environment are merged into and overwrite non-env specific options.

.babelrc:

{
  "presets": ["es2015"],
  "env": {
    "production": {
      "presets": ["minify"]
    }
  }
}

Then you'll need to set the env variable which could be something like BABEL_ENV=production npm run build

Individual Plugins

The minify repo is comprised of many npm packages. It is a lerna monorepo similar to babel itself.

The npm package babel-preset-minify is at the path packages/babel-preset-minify

Package Version Dependencies
babel-plugin-minify-constant-folding npm Dependency Status
babel-plugin-minify-dead-code-elimination npm Dependency Status
babel-plugin-minify-flip-comparisons npm Dependency Status
babel-plugin-minify-guarded-expressions npm Dependency Status
babel-plugin-minify-infinity npm Dependency Status
babel-plugin-minify-mangle-names npm Dependency Status
babel-plugin-minify-replace npm Dependency Status
babel-plugin-minify-simplify npm Dependency Status
babel-plugin-minify-type-constructors npm Dependency Status
babel-plugin-transform-member-expression-literals npm Dependency Status
babel-plugin-transform-merge-sibling-variables npm Dependency Status
babel-plugin-transform-minify-booleans npm Dependency Status
babel-plugin-transform-property-literals npm Dependency Status
babel-plugin-transform-simplify-comparison-operators npm Dependency Status
babel-plugin-transform-undefined-to-void npm Dependency Status

Usage

Normally you wouldn't be consuming the plugins directly since the preset is available.

Add to your .babelrc's plugins array.

{
  "plugins": ["babel-plugin-transform-undefined-to-void"]
}

Other

Package Version Dependencies
babel-plugin-transform-inline-environment-variables npm Dependency Status
babel-plugin-transform-node-env-inline npm Dependency Status
babel-plugin-transform-remove-console npm Dependency Status
babel-plugin-transform-remove-debugger npm Dependency Status

Benchmarks

Bootstrap: npm run bootstrap

Build: npm run build

Running the benchmarks: ./scripts/benchmark.js [file...] - defaults to a few packages fetched from unpkg.com and is defined in benchmark.js.

Note: All Input sources are ES5.

Benchmark Results for react.js:

Input Size: 54.79KB

Input Size (gzip): 15.11KB

minifier output raw raw win gzip output gzip win parse time (ms) minify time (ms)
babel-minify 15.97KB 71% 6.08KB 60% 1.00 1039.06
terser 15.65KB 71% 5.98KB 60% 0.93 532.19
uglify 15.6KB 72% 6KB 60% 1.09 463.69
closure-compiler 15.74KB 71% 6.04KB 60% 1.22 2361.41
closure-compiler-js 18.21KB 67% 6.73KB 55% 1.08 3381.47

Benchmark Results for vue.js:

Input Size: 282.52KB

Input Size (gzip): 77.52KB

minifier output raw raw win gzip output gzip win parse time (ms) minify time (ms)
babel-minify 104.21KB 63% 38.71KB 50% 6.09 3538.30
terser 103.12KB 63% 37.92KB 51% 6.42 1680.85
uglify 102.71KB 64% 38.08KB 51% 6.59 1662.50
closure-compiler 101.93KB 64% 38.6KB 50% 10.41 4413.06
closure-compiler-js 105.18KB 63% 39.5KB 49% 6.79 12082.80

Benchmark Results for lodash.js:

Input Size: 527.18KB

Input Size (gzip): 94.04KB

minifier output raw raw win gzip output gzip win parse time (ms) minify time (ms)
babel-minify 69.59KB 87% 24.37KB 74% 5.38 2587.27
terser 68.66KB 87% 24.31KB 74% 6.41 1913.43
uglify 68.15KB 87% 24.05KB 74% 5.89 2075.71
closure-compiler 71.05KB 87% 24.19KB 74% 6.24 4119.43
closure-compiler-js 73.51KB 86% 24.94KB 73% 5.17 9650.59

Benchmark Results for three.js:

Input Size: 1.05MB

Input Size (gzip): 212.43KB

minifier output raw raw win gzip output gzip win parse time (ms) minify time (ms)
babel-minify 535.88KB 50% 134.66KB 37% 27.24 9988.57
terser 536.16KB 50% 132.78KB 37% 28.39 3919.34
uglify 533.42KB 50% 133.21KB 37% 26.15 4025.20
closure-compiler 532.44KB 51% 134.41KB 37% 29.96 9029.19
closure-compiler-js 543.08KB 50% 136.3KB 36% 24.36 95743.77

Browser support

Babel Minify is best at targeting latest browsers (with full ES6+ support) but can also be used with the usual Babel es2015 preset to transpile down the code first.

Team

Amjad Masad Boopathi Rajaa Juriy Zaytsev Henry Zhu Vignesh Shanmugam
Amjad Masad Boopathi Rajaa Juriy Zaytsev Henry Zhu Vignesh Shanmugam
@amasad @boopathi @kangax @hzoo @vigneshshanmugam
@amasad @heisenbugger @kangax @left_pad @_vigneshh