babel-preset-babili

Babel preset for all minify plugins.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-preset-babili
0.1.45 years ago6 years agoMinified + gzip package size for babel-preset-babili in KB

Readme

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

Two types of options:
  1. 1-1 mapping with plugin
  2. The same option passed to multiple plugins

1-1 mapping with plugin

  • false - disable plugin
  • true - enable plugin
  • { ...pluginOpts } - enable plugin and pass pluginOpts to plugin

OptionName | Plugin | DefaultValue ---------- | ------ | ------------ booleans | transform-minify-booleansbooleans | true builtIns | minify-builtinsbuiltIns | true consecutiveAdds | transform-inline-consecutive-addsconsecutiveAdds | true deadcode | minify-dead-code-eliminationdeadcode | true evaluate | minify-constant-foldingevaluate | true flipComparisons | minify-flip-comparisonsflipComparisons | true guards | minify-guarded-expressionsguards | true infinity | minify-infinityinfinity | true mangle | minify-mangle-namesmangle | true memberExpressions | transform-member-expression-literalsmemberExpressions | true mergeVars | transform-merge-sibling-variablesmergeVars | true numericLiterals | minify-numeric-literalsnumericLiterals | true propertyLiterals | transform-property-literalspropertyLiterals | true regexpConstructors | transform-regexp-constructorsregexpConstructors | true removeConsole | transform-remove-consoleremoveConsole | false removeDebugger | transform-remove-debuggerremoveDebugger | false removeUndefined | transform-remove-undefinedremoveUndefined | true replace | minify-replacereplace | true simplify | minify-simplifysimplify | true simplifyComparisons | transform-simplify-comparison-operatorssimplifyComparisons | true typeConstructors | minify-type-constructorstypeConstructors | true undefinedToVoid | transform-undefined-to-voidundefinedToVoid | true

The same option passed to multiple plugins

  • When multiple plugins require the same option, it's easier to declare it in one place. These options are passed on to two or more plugins.

OptionName | Plugins ---------- | ------- keepFnName | Passed to manglemangle & deadcodedeadcode keepClassName | Passed to manglemangle & deadcodedeadcode
Examples
{
  "presets": [["babili", {
    "evaluate": false,
    "mangle": true
  }]]
}

{
  "presets": [["babili", {
    "mangle": {
      "blacklist": ["ParserError", "NetworkError"]
    }
  }]]
}

{
  "presets": [["babili", {
    "keepFnName": true
  }]]
}
// is the same as
{
  "presets": [["babili", {
    "mangle": {
      "keepFnName": true
    },
    "deadcode": {
      "keepFnName": true
    }
  }]]
}