# babel-preset-minify

> Babel preset for all minify plugins.

Latest version **0.5.2** (published 2022-05-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-preset-minify
pnpm add babel-preset-minify
yarn add babel-preset-minify
bun add babel-preset-minify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2022-05-06 |
| First published | 2016-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 23 |
| Unpacked size | 15.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4371 |
| Author | amasad |
| Maintainers | nicolo-ribaudo, boopathi, hzoo, vignesh.shanmugam, loganfsmyth |
| Keywords | babel-minify, babel-preset, minify |

## Links

- npm: https://www.npmjs.com/package/babel-preset-minify
- Repository: https://github.com/babel/minify/tree/master/packages/babel-preset-minify
- Homepage: https://github.com/babel/minify#readme
- Issues: https://github.com/babel/minify/issues
- npm.io page: https://npm.io/package/babel-preset-minify

## Dependencies (23)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [babel-plugin-minify-replace](https://npm.io/package/babel-plugin-minify-replace.md) ^0.5.0
- [babel-plugin-minify-builtins](https://npm.io/package/babel-plugin-minify-builtins.md) ^0.5.0
- [babel-plugin-minify-infinity](https://npm.io/package/babel-plugin-minify-infinity.md) ^0.4.3
- [babel-plugin-minify-simplify](https://npm.io/package/babel-plugin-minify-simplify.md) ^0.5.1
- [babel-plugin-minify-mangle-names](https://npm.io/package/babel-plugin-minify-mangle-names.md) ^0.5.1
- [babel-plugin-minify-constant-folding](https://npm.io/package/babel-plugin-minify-constant-folding.md) ^0.5.0
- [babel-plugin-minify-flip-comparisons](https://npm.io/package/babel-plugin-minify-flip-comparisons.md) ^0.4.3
- [babel-plugin-minify-numeric-literals](https://npm.io/package/babel-plugin-minify-numeric-literals.md) ^0.4.3
- [babel-plugin-minify-type-constructors](https://npm.io/package/babel-plugin-minify-type-constructors.md) ^0.4.3
- [babel-plugin-transform-remove-console](https://npm.io/package/babel-plugin-transform-remove-console.md) ^6.9.4
- [babel-plugin-transform-minify-booleans](https://npm.io/package/babel-plugin-transform-minify-booleans.md) ^6.9.4
- [babel-plugin-transform-remove-debugger](https://npm.io/package/babel-plugin-transform-remove-debugger.md) ^6.9.4
- [babel-plugin-minify-guarded-expressions](https://npm.io/package/babel-plugin-minify-guarded-expressions.md) ^0.4.4
- [babel-plugin-transform-remove-undefined](https://npm.io/package/babel-plugin-transform-remove-undefined.md) ^0.5.0
- [babel-plugin-transform-property-literals](https://npm.io/package/babel-plugin-transform-property-literals.md) ^6.9.4
- [babel-plugin-transform-undefined-to-void](https://npm.io/package/babel-plugin-transform-undefined-to-void.md) ^6.9.4
- [babel-plugin-minify-dead-code-elimination](https://npm.io/package/babel-plugin-minify-dead-code-elimination.md) ^0.5.2
- [babel-plugin-transform-regexp-constructors](https://npm.io/package/babel-plugin-transform-regexp-constructors.md) ^0.4.3
- [babel-plugin-transform-inline-consecutive-adds](https://npm.io/package/babel-plugin-transform-inline-consecutive-adds.md) ^0.4.3
- [babel-plugin-transform-merge-sibling-variables](https://npm.io/package/babel-plugin-transform-merge-sibling-variables.md) ^6.9.5
- [babel-plugin-transform-member-expression-literals](https://npm.io/package/babel-plugin-transform-member-expression-literals.md) ^6.9.4
- [babel-plugin-transform-simplify-comparison-operators](https://npm.io/package/babel-plugin-transform-simplify-comparison-operators.md) ^6.9.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2022-05-06
- 0.6.0-alpha.9 (canary) — 2019-08-15
- 0.5.1 — 2019-08-15
- 0.6.0-alpha.8 — 2019-08-15
- 0.6.0-alpha.5 — 2018-10-29
- 0.6.0-alpha.4 — 2018-10-29
- 0.5.0 — 2018-09-24
- 0.5.0-alpha.9 — 2018-09-23
- 0.5.0-alpha.3cc09dcf — 2018-07-27
- 0.5.0-alpha.beb87b9a — 2018-07-26
- 0.5.0-alpha.5a128fd5 — 2018-07-17
- 0.5.0-alpha.2ed85317 — 2018-07-17
- 0.5.0-alpha.a24dd066 — 2018-06-11
- 0.5.0-alpha.2e0de171 — 2018-06-01
- 0.5.0-alpha.89fc69da — 2018-06-01
- … 65 more at https://npm.io/package/babel-preset-minify/versions

## README

# babel-preset-minify

Babel preset for all minify plugins.

+ [Install](#install)
+ [Usage](#usage)
+ [Options](#options)

## Install

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

## Usage

### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
  "presets": ["minify"]
}
```

or pass in options -

```json
{
  "presets": [["minify", {
    "mangle": {
      "exclude": ["MyCustomError"]
    },
    "unsafe": {
      "typeConstructors": false
    },
    "keepFnName": true
  }]]
}
```

### Via CLI

```sh
babel script.js --presets minify
```

### Via Node API

```javascript
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-booleans][booleans]                          | true
builtIns            | [minify-builtins][builtIns]                                    | true
consecutiveAdds     | [transform-inline-consecutive-adds][consecutiveAdds]           | true
deadcode            | [minify-dead-code-elimination][deadcode]                       | true
evaluate            | [minify-constant-folding][evaluate]                            | true
flipComparisons     | [minify-flip-comparisons][flipComparisons]                     | true
guards              | [minify-guarded-expressions][guards]                           | true
infinity            | [minify-infinity][infinity]                                    | true
mangle              | [minify-mangle-names][mangle]                                  | true
memberExpressions   | [transform-member-expression-literals][memberExpressions]      | true
mergeVars           | [transform-merge-sibling-variables][mergeVars]                 | true
numericLiterals     | [minify-numeric-literals][numericLiterals]                     | true
propertyLiterals    | [transform-property-literals][propertyLiterals]                | true
regexpConstructors  | [transform-regexp-constructors][regexpConstructors]            | true
removeConsole       | [transform-remove-console][removeConsole]                      | false
removeDebugger      | [transform-remove-debugger][removeDebugger]                    | false
removeUndefined     | [transform-remove-undefined][removeUndefined]                  | true
replace             | [minify-replace][replace]                                      | true
simplify            | [minify-simplify][simplify]                                    | true
simplifyComparisons | [transform-simplify-comparison-operators][simplifyComparisons] | true
typeConstructors    | [minify-type-constructors][typeConstructors]                   | true
undefinedToVoid     | [transform-undefined-to-void][undefinedToVoid]                 | 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 [mangle][mangle] & [deadcode][deadcode]
keepClassName       | Passed to [mangle][mangle] & [deadcode][deadcode]
tdz                 | Passed to [builtIns][builtIns], [evaluate][evaluate], [deadcode][deadcode], [removeUndefined][removeUndefined]

**Examples**

```json
{
  "presets": [["minify", {
    "evaluate": false,
    "mangle": true
  }]]
}
```

```json
{
  "presets": [["minify", {
    "mangle": {
      "exclude": ["ParserError", "NetworkError"]
    }
  }]]
}
```

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

[booleans]: ../../packages/babel-plugin-transform-minify-booleans
[builtIns]: ../../packages/babel-plugin-minify-builtins
[consecutiveAdds]: ../../packages/babel-plugin-transform-inline-consecutive-adds
[deadcode]: ../../packages/babel-plugin-minify-dead-code-elimination
[evaluate]: ../../packages/babel-plugin-minify-constant-folding
[flipComparisons]: ../../packages/babel-plugin-minify-flip-comparisons
[guards]: ../../packages/babel-plugin-minify-guarded-expressions
[infinity]: ../../packages/babel-plugin-minify-infinity
[mangle]: ../../packages/babel-plugin-minify-mangle-names
[memberExpressions]: ../../packages/babel-plugin-transform-member-expression-literals
[mergeVars]: ../../packages/babel-plugin-transform-merge-sibling-variables
[numericLiterals]: ../../packages/babel-plugin-minify-numeric-literals
[propertyLiterals]: ../../packages/babel-plugin-transform-property-literals
[regexpConstructors]: ../../packages/babel-plugin-transform-regexp-constructors
[removeConsole]: ../../packages/babel-plugin-transform-remove-console
[removeDebugger]: ../../packages/babel-plugin-transform-remove-debugger
[removeUndefined]: ../../packages/babel-plugin-transform-remove-undefined
[replace]: ../../packages/babel-plugin-minify-replace
[simplify]: ../../packages/babel-plugin-minify-simplify
[simplifyComparisons]: ../../packages/babel-plugin-transform-simplify-comparison-operators
[typeConstructors]: ../../packages/babel-plugin-minify-type-constructors
[undefinedToVoid]: ../../packages/babel-plugin-transform-undefined-to-void

---
_Source: https://npm.io/package/babel-preset-minify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
