0.5.2 • Published 3 years ago

babel-preset-minify v0.5.2

Weekly downloads
2,228,733
License
MIT
Repository
github
Last release
3 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-generatorswan-app-clisyz-clitest-plugin-foodpageweb-module-scriptwebcubewebpack-vue-ylushenwrite-j2cxcl1wheelhouse-packagerwxdtxhs-mp-compiler-new-clitemplate-extract-pluginstorybook-vue-hmr-fixstart-deepsweet-react-components-monorepo-presetstop14-themesystem-legacystorybook-core-tmpsushiwebthink-axios@digitalmaster/react@croquiscom/storybook-app-mithril@croquiscom/storybook-app-mithril-2@cscart/tools@complat/nmr_displayer@copart/backoffice-charges-module@dadi/cdn@data-ui/build-config@develephant/corona-html5-node-kit@demo-services/demo-image-service@demo-services/demo-layer-test@demiazz/brandon@beisen/storybook-core@candour/fluid@candour/step@pearsonedunext/frontend-component-cookie-policy-banner@powership/boilerplatejfa-pwa-toolkitjinghuan-clijnpkgipo-cliippan-app-manageriroha-helpers-new-grpciroha-helpers-tsiroha-helpersiroha-helpers-eugeneiroha-helpers-eugene0ipsadelenitiisotropic-dev-dependenciesisomorph-webkaskykoa-esm-transformkkt-serverless-plugin-optimizelasso-babel-minifylapanoid-storybook-react-nativehschmaiske-babelstrix-jsstreamsoftco-developmentsse-file-saverstephanemw-storybook-depttsds-serverless-optimizeu-libraryxhs-mp-compiler-clitoloframeworkutility-reactlibraryvue-packery-draggabilly-plugin@aomi/webapp-cli@appdirect/sfb-toolkit@ardatan/meteor-babel@ahassani/validate@azinepages/common@balumoorthi/react-master-components@beeant/ocisrc@bdna/w3-tools@agneta/platform@blackdice/storybook-react-native@bixi/builder@bixi-react/builder@bloometry/step@bloometry/fluid@bleushan/babel-preset-env
0.5.2

3 years ago

0.6.0-alpha.9

6 years ago

0.5.1

6 years ago

0.6.0-alpha.8

6 years ago

0.6.0-alpha.5

7 years ago

0.6.0-alpha.4

7 years ago

0.5.0

7 years ago

0.5.0-alpha.9

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

8 years ago

0.0.0

9 years ago