1 | # babel-minify
|
2 |
|
3 | Node API and CLI
|
4 |
|
5 | [![npm](https://img.shields.io/npm/v/babel-minify.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-minify)
|
6 |
|
7 | Use `babel-minify` if you don't already use babel (as a preset) or want to run it standalone.
|
8 |
|
9 | ## Installation
|
10 |
|
11 | ```sh
|
12 | npm install babel-minify --save-dev
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 |
|
17 | ### Node API
|
18 |
|
19 | ```js
|
20 | const minify = require("babel-minify");
|
21 |
|
22 | const {code, map} = minify("input code", {
|
23 | mangle: {
|
24 | keepClassName: true
|
25 | }
|
26 | });
|
27 | ```
|
28 |
|
29 | ### CLI
|
30 |
|
31 | ```sh
|
32 | minify input.js --out-file input.min.js --mangle.keepClassName
|
33 | ```
|
34 |
|
35 | ## Node API
|
36 |
|
37 | ```js
|
38 | const minify = require("babel-minify");
|
39 |
|
40 | minify(input, minifyOptions, overrides)
|
41 | ```
|
42 |
|
43 | ### minifyOptions
|
44 |
|
45 | Refer [babel-preset-minify options](https://github.com/babel/minify/tree/master/packages/babel-preset-minify#options)
|
46 |
|
47 | ### overrides
|
48 |
|
49 | + `babel`: Custom babel
|
50 | + `minifyPreset`: Custom minify preset
|
51 | + `inputSourceMap`: Input Sourcemap
|
52 | + `sourceMaps`: [Boolean]
|
53 | + `comments`: [Function | RegExp | Boolean]
|
54 |
|
55 | ## CLI Options
|
56 |
|
57 | ```
|
58 | minify input.js [options]
|
59 | ```
|
60 |
|
61 | ### Simple preset options
|
62 |
|
63 | For simple options, use `--optionName` in CLI
|
64 |
|
65 | Refer [preset's 1-1 options](https://github.com/babel/minify/tree/master/packages/babel-preset-minify#1-1-mapping-with-plugin) for the list of options
|
66 |
|
67 | Example:
|
68 |
|
69 | ```
|
70 | minify input.js --mangle false
|
71 | ```
|
72 |
|
73 | ### Nested preset options
|
74 |
|
75 | Usage: `--optionName.featureName`
|
76 |
|
77 | Example:
|
78 |
|
79 | ```sh
|
80 | minify input.js --mangle.keepClassName --deadcode.keepFnArgs --outFile input.min.js
|
81 | ```
|
82 |
|
83 | Refer the corresponding plugins to know the list of options it takes
|
84 |
|
85 | ### IO options
|
86 |
|
87 | + `--out-file path/to/file.min.js`: Output filename. Used only when reading from STDIN / a single input file
|
88 | + `--out-dir path/to/dir`: Output Directory.
|