babel-preset-minify

Babel preset for all minify plugins.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-preset-minify
0.5.22 years ago8 years agoMinified + gzip package size for babel-preset-minify in KB

Readme

babel-preset-minify
Babel preset for all minify plugins.

Install

npm install babel-preset-minify --save-dev

Usage

Via .babelrc (Recommended)

.babelrc
{
  "presets": ["minify"]
}

or pass in options -
{
  "presets": [["minify", {
    "mangle": {
      "exclude": ["MyCustomError"]
    },
    "unsafe": {
      "typeConstructors": false
    },
    "keepFnName": true
  }]]
}

Via CLI

babel script.js --presets minify

Via Node API

const babel = require("@babel/core");
const fs = require("fs");

const code = fs.readFileSync("./input.js").toString();

const minified = babel.transform(code, {
  presets: ["minify"]
});

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 tdz | Passed to builtInsbuiltIns, evaluateevaluate, deadcodedeadcode, removeUndefinedremoveUndefined
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
    }
  }]]
}