Babel preset for all minify plugins.
$ npm install --save-dev babel-preset-babili
.babelrc
{
"presets": ["babili"]
}
or pass in options -
{
"presets": [["babili", {
"mangle": {
"blacklist": ["MyCustomError"]
},
"unsafe": {
"typeConstructors": false
},
"keepFnName": true
}]]
}
$ babel script.js --presets babili
require("babel-core").transform("code", {
presets: ["babili"]
});
All options are enabled by default except the ones with explicit mention - (Default: false)
Three types of options:
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,
evaluate
- babel-plugin-minify-constant-foldingdeadcode
- babel-plugin-minify-dead-code-eliminationinfinity
- babel-plugin-minify-infinitymangle
- babel-plugin-minify-mangle-namesnumericLiterals
- babel-plugin-minify-numeric-literalsreplace
- babel-plugin-minify-replacesimplify
- babel-plugin-minify-simplifymergeVars
- babel-plugin-transform-merge-sibling-variablesbooleans
- babel-plugin-transform-minify-booleansregexpConstructors
- babel-plugin-transform-regexp-constructorsremoveConsole
-(Default: false)
- babel-plugin-transform-remove-consoleremoveDebugger
-(Default: false)
- babel-plugin-transform-remove-debuggerremoveUndefined
- babel-plugin-transform-remove-undefinedundefinedToVoid
- babel-plugin-transform-undefined-to-void
Examples
{
"presets": [["babili", {
"evaluate": false,
"mangle": true
}]]
}
{
"presets": [["babili", {
"mangle": {
"blacklist": [
"ParserError",
"NetworkError"
]
}
}]]
}
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 -
unsafe
flipComparisons
- babel-plugin-minify-flip-comparisonssimplifyComparisons
- babel-plugin-transform-simplify-comparison-operatorsguards
- babel-plugin-minify-guarded-expressionstypeConstructors
- babel-plugin-minify-type-constructors
properties
memberExpressions
- babel-plugin-transform-member-expression-literalspropertyLiterals
- babel-plugin-transform-property-literals
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
}
}]]
}
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 tomangle
anddeadcode
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
}
}]]
}