Skip to content

Repository files navigation

babel-minify

An ES6+ aware minifier based on the Babel toolchain.

NPM VersionTravis StatusCircleCI StatusAppveyorCI StatusCode CoverageSlack StatusNPM Downloads

Note

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

Table of Contents

Requirements

  • node >= 4
  • 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 CodeclassMangler{constructor(program){this.program=program;}}newMangler();// without this it would just output nothing since Mangler isn't used

Before

// ES2015+ code -> Babel -> BabelMinify/Uglify -> Minified ES5 Codevara=functiona(b){_classCallCheck(this,a),this.program=b};newa;

After

// ES2015+ code -> BabelMinify -> Minified ES2015+ Codeclassa{constructor(b){this.program=b}}newa;
PackageVersionDependencies
babel-minifynpmDependency Status

Install

npm install babel-minify --save-dev

Usage

minify src -d lib
PackageVersionDependencies
babel-preset-minifynpmDependency 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

PackageVersionDependencies
babel-plugin-minify-constant-foldingnpmDependency Status
babel-plugin-minify-dead-code-eliminationnpmDependency Status
babel-plugin-minify-flip-comparisonsnpmDependency Status
babel-plugin-minify-guarded-expressionsnpmDependency Status
babel-plugin-minify-infinitynpmDependency Status
babel-plugin-minify-mangle-namesnpmDependency Status
babel-plugin-minify-replacenpmDependency Status
babel-plugin-minify-simplifynpmDependency Status
babel-plugin-minify-type-constructorsnpmDependency Status
babel-plugin-transform-member-expression-literalsnpmDependency Status
babel-plugin-transform-merge-sibling-variablesnpmDependency Status
babel-plugin-transform-minify-booleansnpmDependency Status
babel-plugin-transform-property-literalsnpmDependency Status
babel-plugin-transform-simplify-comparison-operatorsnpmDependency Status
babel-plugin-transform-undefined-to-voidnpmDependency 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

PackageVersionDependencies
babel-plugin-transform-inline-environment-variablesnpmDependency Status
babel-plugin-transform-node-env-inlinenpmDependency Status
babel-plugin-transform-remove-consolenpmDependency Status
babel-plugin-transform-remove-debuggernpmDependency 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: 141.63kB

Input Size (gzip): 33.66kB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify40.63kB71%13.33kB60%2.491905.17
uglify40.34kB72%13.12kB61%2.30784.33
closure-compiler39.45kB72%13.25kB61%2.622519.02
closure-compiler-js47.23kB67%15.25kB55%3.766730.76
butternut41.94kB70%13.53kB60%2.33275.20

Benchmark Results for vue.js:

Input Size: 258.76kB

Input Size (gzip): 71.01kB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify97.23kB62%36.09kB49%5.834986.36
uglify96.95kB63%35.99kB49%5.781446.37
closure-compiler95.29kB63%35.8kB50%6.283953.95
closure-compiler-js98.53kB62%36.73kB48%6.0010221.88

Benchmark Results for lodash.js:

Input Size: 526.94kB

Input Size (gzip): 93.91kB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify69.14kB87%24.06kB74%8.374728.87
uglify68.58kB87%24kB74%27.202340.07
closure-compiler70.68kB87%24.11kB74%6.984718.42
closure-compiler-js73.14kB86%24.85kB74%6.578148.38
butternut72.06kB86%25.01kB73%6.95514.93

Benchmark Results for three.js:

Input Size: 1015.5kB

Input Size (gzip): 202.89kB

minifieroutput rawraw wingzip outputgzip winparse time (ms)minify time (ms)
babel-minify497.33kB51%126.74kB38%25.1614465.92
uglify498.59kB51%125.66kB38%26.054419.97
closure-compiler495.7kB51%126.48kB38%34.4010623.86
closure-compiler-js504.11kB50%127.84kB37%28.59115045.71
butternut505.93kB50%127.09kB37%31.121349.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 MasadBoopathi RajaaJuriy ZaytsevHenry ZhuVignesh Shanmugam
Amjad MasadBoopathi RajaaJuriy ZaytsevHenry ZhuVignesh Shanmugam
@amasad@boopathi@kangax@hzoo@vigneshshanmugam
@amasad@heisenbugger@kangax@left_pad@_vigneshh

About

✂️ An ES6+ aware minifier based on the Babel toolchain (beta)

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages