• Stars
    star
    4,391
  • Rank 9,755 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โœ‚๏ธ An ES6+ aware minifier based on the Babel toolchain (beta)

babel-minify (beta)

An ES6+ aware minifier based on the Babel toolchain.

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

  • babel-minify is consumable via API, CLI, or Babel preset. Try it online - babeljs.io/repl

Historical note: babel-minify was renamed from babili.

Table of Contents

Experimental

babel-minify is an experimental project that attempts to use Babel's toolchain (for compilation) to do something in a similar vein, minification. It's currently in 0.x, so we don't recommend using it in production.

Checkout our CONTRIBUTING.md if you want to help out!

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

note: minify is still in beta, so we don't recommend using it for production code but rather the production environment.

When testing, it's recommended to run minifiers for production so less code is sent to end-users vs. in development where it can be an issue for readability when debugging. 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

More Repositories

1

babel

๐Ÿ  Babel is a compiler for writing next generation JavaScript.
TypeScript
43,141
star
2

babel-loader

๐Ÿ“ฆ Babel loader for webpack
JavaScript
4,824
star
3

babel-preset-env

PSA: this repo has been moved into babel/babel -->
JavaScript
3,500
star
4

babel-sublime

Syntax definitions for ES6 JavaScript with React JSX extensions.
JavaScript
3,256
star
5

babel-eslint

๐Ÿ—ผ A wrapper for Babel's parser used for ESLint (renamed to @babel/eslint-parser)
JavaScript
2,963
star
6

example-node-server

Example Node Server w/ Babel
JavaScript
2,844
star
7

babylon

PSA: moved into babel/babel as @babel/parser -->
JavaScript
1,714
star
8

babelify

Browserify transform for Babel
JavaScript
1,680
star
9

gulp-babel

Gulp plugin for Babel
JavaScript
1,320
star
10

babel-upgrade

โฌ†๏ธ A tool for upgrading Babel versions (to v7): `npx babel-upgrade`
JavaScript
1,309
star
11

awesome-babel

๐Ÿ˜ŽA list of awesome Babel plugins, presets, etc.
864
star
12

babel-standalone

๐ŸŽฎ Now located in the Babel repo! Standalone build of Babel for use in non-Node.js environments, including browsers.
JavaScript
819
star
13

website

๐ŸŒ The Babel documentation website
TypeScript
749
star
14

preset-modules

A Babel preset that targets modern browsers by fixing engine bugs (will be merged into preset-env eventually)
JavaScript
739
star
15

kneden

Transpile ES2017 async/await to vanilla ES6 Promise chains: a Babel plugin
JavaScript
514
star
16

grunt-babel

Grunt plugin for Babel
JavaScript
437
star
17

proposals

โœ๏ธ Tracking the status of Babel's implementation of TC39 proposals (may be out of date)
432
star
18

eslint-plugin-babel

An ESlint rule plugin companion to babel-eslint
JavaScript
389
star
19

generator-babel-boilerplate

A Yeoman generator to author libraries in ES2015 (and beyond!) for Node and the browser.
JavaScript
381
star
20

babel-time-travel

Time travel through babel transformations one by one (implemented in the Babel REPL now)
JavaScript
344
star
21

babel-polyfills

A set of Babel plugins that enable injecting different polyfills with different strategies in your compiled code.
TypeScript
330
star
22

babel-sublime-snippets

Next generation JavaScript and React snippets for Sublime
263
star
23

karma-babel-preprocessor

Karma plugin for Babel
JavaScript
167
star
24

ruby-babel-transpiler

Ruby Babel is a bridge to the JS Babel transpiler.
Ruby
159
star
25

babel-jest

Jest plugin for Babel (moved) ->
138
star
26

notes

โ™ฌ Notes from the @Babel Team (discuss in PRs)
122
star
27

generator-babel-plugin

Babel Plugin generator for Yeoman
JavaScript
118
star
28

babel-bridge

A placeholder package that bridges babel-core to @babel/core.
JavaScript
94
star
29

babel-bot

๐Ÿค– A helpful bot to automate common tasks on Babel Issues/PRs
JavaScript
75
star
30

babel-brunch

Brunch plugin for Babel
JavaScript
68
star
31

broccoli-babel-transpiler

Broccoli plugin for Babel
JavaScript
57
star
32

jade-babel

Jade plugin for Babel
JavaScript
40
star
33

sandboxes

Babel repl-like codesandbox: check out link =>
JavaScript
39
star
34

jekyll-babel

A Babel converter for Jekyll.
Ruby
34
star
35

acorn-to-esprima

(unmaintained) Converts acorn tokens to esprima tokens
JavaScript
33
star
36

babel-connect

Connect plugin for Babel
JavaScript
27
star
37

podcast.babeljs.io

The Babel Podcast site!
JavaScript
25
star
38

phabricator-to-github

A tool to migrate phabricator issues to github
JavaScript
24
star
39

actions

Babel specific github actions ๐Ÿค–
JavaScript
24
star
40

rfcs

RFCs for changes to Babel
21
star
41

metalsmith-babel

A Metalsmith plugin to compile JavaScript with Babel
JavaScript
20
star
42

babel-configuration-examples

WIP
JavaScript
18
star
43

logo

Babel logo
15
star
44

duo-babel

Duo plugin for Babel
JavaScript
15
star
45

parser_performance

JavaScript
13
star
46

eslint-config-babel

ESLint config for all Babel repos
JavaScript
10
star
47

gobble-babel

Gobble plugin for Babel
JavaScript
9
star
48

babel-standalone-bower

Bower build of babel-standalone. See https://github.com/Daniel15/babel-standalone
JavaScript
9
star
49

eslint-plugin-babel-plugin

A set of eslint rules to enforce best practices in the development of Babel plugins.
JavaScript
8
star
50

babel-plugin-proposal-private-property-in-object

@babel/plugin-proposal-private-property-in-object, with an added warning for when depending on this package without explicitly listing it in dependencies or devDependencies
JavaScript
8
star
51

babel-archive

๐Ÿ—‘ Packages that are deprecated or don't need to be updated
JavaScript
7
star
52

.github

Community health files for the Babel organization
7
star
53

flavortown

what else?
6
star
54

babel-test262-runner

Run test262 tests on Node 0.10 using Babel 7 and `core-js@3`.
JavaScript
6
star
55

babel-plugin-transform-async-functions

https://github.com/MatAtBread/fast-async/issues/46
4
star
56

phabricator-redirects

โ†ฉ๏ธ Redirects for old phabricator urls
HTML
2
star
57

slack-invite-link

Source of slack.babeljs.io
1
star