0.5.2 • Published 2 years ago

babel-preset-minify v0.5.2

Weekly downloads
2,228,733
License
MIT
Repository
github
Last release
2 years ago

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
OptionNamePluginDefaultValue
booleanstransform-minify-booleanstrue
builtInsminify-builtinstrue
consecutiveAddstransform-inline-consecutive-addstrue
deadcodeminify-dead-code-eliminationtrue
evaluateminify-constant-foldingtrue
flipComparisonsminify-flip-comparisonstrue
guardsminify-guarded-expressionstrue
infinityminify-infinitytrue
mangleminify-mangle-namestrue
memberExpressionstransform-member-expression-literalstrue
mergeVarstransform-merge-sibling-variablestrue
numericLiteralsminify-numeric-literalstrue
propertyLiteralstransform-property-literalstrue
regexpConstructorstransform-regexp-constructorstrue
removeConsoletransform-remove-consolefalse
removeDebuggertransform-remove-debuggerfalse
removeUndefinedtransform-remove-undefinedtrue
replaceminify-replacetrue
simplifyminify-simplifytrue
simplifyComparisonstransform-simplify-comparison-operatorstrue
typeConstructorsminify-type-constructorstrue
undefinedToVoidtransform-undefined-to-voidtrue

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.
OptionNamePlugins
keepFnNamePassed to mangle & deadcode
keepClassNamePassed to mangle & deadcode
tdzPassed 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
    }
  }]]
}
@mohitsingh/staticgatsby-starter-emulsify-drupal@analogyxbi-ui/build-configemulsify-design-system@mojofw/mojo-cli@mojofw/cli@dubb/mickey@analogyxbi/build-config@compensar/proveedores-buildervite-walletlistingslabkeyplug@uinz/gg-scriptsxania-cliweboptimizervisionr-dev@everything-registry/sub-chunk-1207matheusccastroo-babelwebfile-packerreact-application-serversmart-blog-generator@ardatan/meteor-babelant-h5ng-plugin@appdirect/sfb-toolkit@aomi/webapp-clihendawyar-webpack-configgulp-sofa-modulegulp-setuparisenid-jsarkid-js@abear/hnode-tools@ahassani/validate@agneta/platformagneta-platform@adaptcharm/rendergulp-ajslibgulp-ajswebgulp-babel-minify@secundant/webpack-module-babel@socifi/babel-config@weareenvoy/plain-js@weareenvoy/dot-matrix@wctools/build-polymer@tccr/cli@widget-dev/react@mtwzim/serverless-plugin-optimize@neutrinojs/babel-minify-webpack-plugin@node-minify/babel-minify@nexys/babelsetup@nlabs/storybook-react@nlabs/storybook-react-native@oliver-schoendorn/webpack-config-builder@omtty/doc@zenworks/framevuerk-buildergqcabin-service-cliaframe-foo-componentaframe-google-poly-componentaframe-loader-3dtiles-componentaframe-loader-laz-componentaframe-midi-componentaframe-render-order-componentaframe-webcentric-component@yhlighting/yhbuild@zalastax/nolb-babel-preset-m@beisen/storybook-core@bdna/w3-tools@beeant/ocisrcbiaozi@balumoorthi/react-master-componentshschmaiske-babel@azinepages/common@candour/fluid@candour/step@cscart/toolscabin-service-cli@complat/nmr_displayerjinghuan-clibuild-polymerbunchingbotflowboy-smartbrace-js-scriptsbrace-js-scripts-devipo-cliiroha-helpersiroha-helpers-eugeneiroha-helpers-eugene0iroha-helpers-new-grpciroha-helpers-tsipsadelenitiippan-app-manager@croquiscom/storybook-app-mithril@croquiscom/storybook-app-mithril-2manbuncsak-buildcubepackmetalpipemeteor-babelnuxt-thematic
0.5.2

2 years ago

0.6.0-alpha.9

5 years ago

0.5.1

5 years ago

0.6.0-alpha.8

5 years ago

0.6.0-alpha.5

5 years ago

0.6.0-alpha.4

5 years ago

0.5.0

6 years ago

0.5.0-alpha.9

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

7 years ago

0.0.0

8 years ago