UNPKG

2.88 kBMarkdownView Raw
1# babili-webpack-plugin
2
3This is a [webpack plugin](https://webpack.js.org/configuration/plugins/) for Babili.
4
5Babili - A babel based minifier - https://github.com/babel/babili
6
7[![Build Status](https://travis-ci.org/boopathi/babili-webpack-plugin.svg?branch=master)](https://travis-ci.org/boopathi/babili-webpack-plugin) [![npm version](https://badge.fury.io/js/babili-webpack-plugin.svg)](https://badge.fury.io/js/babili-webpack-plugin)
8
9+ [Install](#install)
10+ [Usage](#usage)
11+ [Options](#options)
12+ [Why?](#why)
13
14## Install
15
16```sh
17npm install babili-webpack-plugin --save-dev
18```
19
20## Usage
21
22```js
23// webpack.config.js
24const BabiliPlugin = require("babili-webpack-plugin");
25module.exports = {
26 entry: //...,
27 output: //...,
28 plugins: [
29 new BabiliPlugin(options)
30 ]
31}
32```
33
34## Options
35
36+ `test`: JS file extension regex. Default: `/\.js($|\?)/i`
37+ `comments`: Preserve Comments. Default: `/@preserve|@licen(s|c)e/`. falsy value to remove all comments. Accepts function, object with property test (regex), and values.
38+ `sourceMap`: Default: uses [webpackConfig.devtool](https://webpack.github.io/docs/configuration.html#devtool). Set this to override that.
39+ `babel`: Pass in a custom babel-core instead. `require("babel-core")`
40+ `babili`: Pass in a custom babili preset instead - `require("babel-preset-babili")`.
41
42## Why?
43
44You can also use [babel-loader](https://github.com/babel/babel-loader) for webpack and include `babili` [as a preset](https://github.com/babel/babili#babel-preset) and should be much faster than using this - as babili will operate on smaller file sizes. But then, why does this plugin exist at all? -
45
46+ A webpack loader operates on single files and babili preset as a webpack loader is going to consider each file to be executed directly in the browser global scope (by default) and will not optimize some things in the toplevel scope. This is going to change and you can opt-in to optimize toplevel scope - [babel/babili#210](https://github.com/babel/babili/issues/210), [babel/babili#203](https://github.com/babel/babili/issues/203), etc...
47+ When you exclude `node_modules` from being run through the babel-loader, babili optimizations are not applied to the excluded files as it doesn't pass through the minifier.
48+ When you use the babel-loader with webpack, the code generated by webpack for the module system doesn't go through the loader and is not optimized by babili.
49+ A webpack plugin can operate on the entire chunk/bundle output and can optimize the whole bundle and you can see some differences in minified output. But this will be a lot slower as the file size is usually really huge. So there is [another idea](https://github.com/boopathi/babili-webpack-plugin/issues/8) where we can apply some optimizations as a part of the loader and some optimizations in a plugin.
50
51## LICENSE
52
53MIT
54
55https://boopathi.mit-license.org/2016