babel-preset-babili
Babel preset for all minify plugins.
Install
npm install --save-dev babel-preset-babili
Usage
Via .babelrc
(Recommended)
.babelrc
{
"presets": ["babili"]
}
or pass in options -
{
"presets": [["babili", {
"mangle": {
"blacklist": ["MyCustomError"]
},
"unsafe": {
"typeConstructors": false
},
"keepFnName": true
}]]
}
Via CLI
babel script.js --presets babili
Via Node API
require("babel-core").transform("code", {
presets: ["babili"]
});
Options
All options are enabled by default except the ones with an explicit mention - (Default: false)
Three types of options:
1-1 mapping with plugin
false
to disable the plugintrue
to enable the plugin with default plugin specific options{ ...pluginOpts }
to enable the plugin with custom plugin options
The following options have 1-1 mapping with a plugin,
Examples
{
"presets": [["babili", {
"evaluate": false,
"mangle": true
}]]
}
{
"presets": [["babili", {
"mangle": {
"blacklist": {
"ParserError": true,
"NetworkError": false
}
}
}]]
}
Option groups
false
to disable the entire grouptrue
to enable every plugin in the group{ pluginKey: <1-1 mapping> }
- enable/disable a particular plugin in a group (or) pass options to that plugin
The following are groups of plugins -
Examples
Disables all unsafe plugins:
{
"presets": [["babili", {
"unsafe": false
}]]
}
Disables only minify-guarded-expressions, and enable all other unsafe plugins:
{
"presets": [["babili", {
"unsafe": {
"guards": false
}
}]]
}
Passing same plugin options to multiple plugins
In babili, multiple plugins require the same set of options and it is easier to mention it in one place instead of two.
keepFnName
- This will be passed to mangle
and deadcode
and will NOT be overriden if the same option exists under either mangle or deadcode.
Examples
{
"presets": [["babili", {
"keepFnName": true
}]]
}
is the same as,
Plugins applied:
{
"presets": [["babili", {
"mangle": {
"keepFnName": true
},
"deadcode": {
"keepFnName": true
}
}]]
}