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 |
|
54 | ## CLI Options
|
55 |
|
56 | ```
|
57 | minify input.js [options]
|
58 | ```
|
59 |
|
60 | ### Simple preset options
|
61 |
|
62 | For simple options, use `--optionName` in CLI
|
63 |
|
64 | 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
|
65 |
|
66 | Example:
|
67 |
|
68 | ```
|
69 | minify input.js --mangle false
|
70 | ```
|
71 |
|
72 | ### Nested preset options
|
73 |
|
74 | Usage: `--optionName.featureName`
|
75 |
|
76 | Example:
|
77 |
|
78 | ```sh
|
79 | minify input.js --mangle.keepClassName --deadcode.keepFnArgs --outFile input.min.js
|
80 | ```
|
81 |
|
82 | Refer the corresponding plugins to know the list of options it takes
|
83 |
|
84 | ### IO options
|
85 |
|
86 | + `--out-file path/to/file.min.js`: Output filename. Used only when reading from STDIN / a single input file
|
87 | + `--out-dir path/to/dir`: Output Directory.
|