$ npm install babel-preset-minify
Babel preset for all minify plugins.
npm install --save-dev babel-preset-minify
.babelrc
(Recommended).babelrc
{
"presets": ["minify"]
}
or pass in options -
{
"presets": [["minify", {
"mangle": {
"exclude": ["MyCustomError"]
},
"unsafe": {
"typeConstructors": false
},
"keepFnName": true
}]]
}
babel script.js --presets minify
require("@babel/core").transform("code", {
presets: ["minify"]
});
Two types of options:
false
- disable plugintrue
- enable plugin{ ...pluginOpts }
- enable plugin and pass pluginOpts to pluginOptionName | Plugin | DefaultValue |
---|---|---|
booleans | transform-minify-booleans | true |
builtIns | minify-builtins | true |
consecutiveAdds | transform-inline-consecutive-adds | true |
deadcode | minify-dead-code-elimination | true |
evaluate | minify-constant-folding | true |
flipComparisons | minify-flip-comparisons | true |
guards | minify-guarded-expressions | true |
infinity | minify-infinity | true |
mangle | minify-mangle-names | true |
memberExpressions | transform-member-expression-literals | true |
mergeVars | transform-merge-sibling-variables | true |
numericLiterals | minify-numeric-literals | true |
propertyLiterals | transform-property-literals | true |
regexpConstructors | transform-regexp-constructors | true |
removeConsole | transform-remove-console | false |
removeDebugger | transform-remove-debugger | false |
removeUndefined | transform-remove-undefined | true |
replace | minify-replace | true |
simplify | minify-simplify | true |
simplifyComparisons | transform-simplify-comparison-operators | true |
typeConstructors | minify-type-constructors | true |
undefinedToVoid | transform-undefined-to-void | true |
OptionName | Plugins |
---|---|
keepFnName | Passed to mangle & deadcode |
keepClassName | Passed to mangle & deadcode |
tdz | Passed to builtIns, evaluate, deadcode, removeUndefined |
Examples
{
"presets": [["minify", {
"evaluate": false,
"mangle": true
}]]
}
{
"presets": [["minify", {
"mangle": {
"exclude": ["ParserError", "NetworkError"]
}
}]]
}
{
"presets": [["minify", {
"keepFnName": true
}]]
}
// is the same as
{
"presets": [["minify", {
"mangle": {
"keepFnName": true
},
"deadcode": {
"keepFnName": true
}
}]]
}
© 2010 - cnpmjs.org x YWFE | Home | YWFE