Coder Social home page Coder Social logo

eric013 / babili Goto Github PK

View Code? Open in Web Editor NEW

This project forked from babel/minify

0.0 3.0 0.0 9.75 MB

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)

Home Page: https://babeljs.io/repl

License: MIT License

JavaScript 93.59% Shell 0.20% Python 6.21%

babili's Introduction

babili (babel-minify)

An ES6+ aware minifier based on the Babel toolchain.

NPM Version Travis Status Slack Status NPM Downloads

Table of Contents

Requirements

  • node >= 4
  • babel >= 6.20.0

Why

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

  • Babili 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 -> Babili/Uglify -> Minified ES5 Code
var a=function a(b){_classCallCheck(this,a),this.program=b};new a;

After

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

CLI

Package Version Dependencies
babili npm Dependency Status

This is simple wrapper around the regular babel-cli and thus takes in the same cli options as running babel on its own. You can use this if you don't already use babel or want to run it standalone.

Install

npm install babili --save-dev

Usage

babili src -d lib

Equivalent to:

babel src -d lib --presets=babili --no-babelrc

Note that, because the babili command uses the default preset with no-babelrc, you cannot set any non-default options in the preset's plugins with this command. To do this, you can use the babel command with the options set in a .babelrc. See the preset docs for more information on how to do this.

Babel preset

Package Version Dependencies
babel-preset-babili npm Dependency Status

Install

npm install babel-preset-babili --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": ["babili"]
    }
  }
}

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

Individual Plugins

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

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

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 <package>[@version] [relative-path/file.js] - defaults to the package's main file if no file provided.

Backbone.js v1.2.3:

           raw     raw win gzip   gzip win parse time run
uglify              21.68kB 222%    7.26kB 170%     2ms        231ms
closure             21.57kB 223%    7.33kB 168%     2ms        1230ms
babili (best speed) 21.81kB 220%    7.44kB 163%     2ms        747ms
babili (best size)  21.81kB 220%    7.44kB 163%     2ms        600ms
closure js          23.9kB  192%    8kB    145%     2ms        2128ms

Run with: ./scripts/benchmark.js [email protected]

React v0.14.3:

          raw      raw win gzip    gzip win parse time run
closure             171.46kB 265%    52.97kB 168%     13ms       2637ms
uglify              176.36kB 255%    53.13kB 167%     11ms       1148ms
babili (best speed) 176.67kB 255%    55.1kB  157%     12ms       4139ms
babili (best size)  176.67kB 255%    55.1kB  157%     15ms       3683ms
closure js          312.64kB 100%    70.86kB 100%     14ms       1363ms

Run with: ./scripts/benchmark.js [email protected] react/dist/react.js

jQuery v1.11.3:

           raw      raw win gzip    gzip win parse time run
uglify              94.27kB  195%    32.78kB 153%     8ms        850ms
closure             94.14kB  195%    33.38kB 148%     10ms       1905ms
closure js          95.64kB  190%    33.78kB 146%     7ms        6934ms
babili (best speed) 102.78kB 170%    35.32kB 135%     8ms        4563ms
babili (best size)  102.78kB 170%    35.32kB 135%     7ms        4261ms

Run with: ./scripts/benchmark.js [email protected]

Three.js:

           raw      raw win gzip     gzip win parse time run
closure             472.57kB 107%    122.22kB 61%      34ms       4767ms
uglify              478.79kB 104%    122.53kB 61%      34ms       2781ms
closure js          480.11kB 104%    123.44kB 60%      32ms       65423ms
babili (best speed) 506.99kB 93%     128.22kB 54%      39ms       13503ms
babili (best size)  506.99kB 93%     128.22kB 54%      32ms       12605ms

Run with: ./scripts/benchmark.js [email protected] three/build/three.js

Browser support

Babili 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 ---|---|---|---|---| Amjad Masad | Boopathi Rajaa | Juriy Zaytsev | Henry Zhu | @amasad | @boopathi | @kangax | @hzoo @amasad | @heisenbugger | @kangax | @left_pad

babili's People

Contributors

amasad avatar bfred-it avatar boopathi avatar chrisvasz avatar daniel15 avatar dominator008 avatar erikdesjardins avatar existentialism avatar gigabo avatar goto-bus-stop avatar haroenv avatar hzlmn avatar hzoo avatar jamiebuilds avatar josephfrazier avatar kaicataldo avatar kangax avatar kittens avatar mathiasbynens avatar probins avatar renaesop avatar rossipedia avatar sebmck avatar shinew avatar simonselg avatar sixinli avatar tombyrer avatar vigneshshanmugam avatar xtuc avatar ykzts avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.