Socket
Socket
Sign inDemoInstall

babel-preset-minify

Package Overview
Dependencies
31
Maintainers
5
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-preset-minify

Babel preset for all minify plugins.


Version published
Weekly downloads
428K
increased by3.53%
Maintainers
5
Install size
1.71 MB
Created
Weekly downloads
 

Readme

Source

babel-preset-minify

Babel preset for all minify plugins.

  • Install
  • Usage
  • Options

Install

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

Usage

.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
    }
  }]]
}

Keywords

FAQs

Last updated on 06 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc