0
# Configuration
1
2
Comprehensive configuration system providing fine-grained control over parsing, compression, mangling, and output formatting with extensive option categories and intelligent defaults.
3
4
## Capabilities
5
6
### Minify Options Interface
7
8
Main configuration interface that controls all aspects of the minification process.
9
10
```typescript { .api }
11
interface MinifyOptions {
12
/** Enable/configure code compression and optimization */
13
compress?: boolean | CompressOptions;
14
/** ECMAScript target version for parsing and output */
15
ecma?: ECMA;
16
/** Wrap code in anonymous function with configurable parameters */
17
enclose?: boolean | string;
18
/** Support for Internet Explorer 8 compatibility */
19
ie8?: boolean;
20
/** Preserve class names during mangling */
21
keep_classnames?: boolean | RegExp;
22
/** Preserve function names during mangling */
23
keep_fnames?: boolean | RegExp;
24
/** Enable/configure variable and function name mangling */
25
mangle?: boolean | MangleOptions;
26
/** Treat input as ES6 module */
27
module?: boolean;
28
/** Cache object for preserving mangled names across multiple runs */
29
nameCache?: object;
30
/** Configure output code formatting */
31
format?: FormatOptions;
32
/** @deprecated Use format instead */
33
output?: FormatOptions;
34
/** Configure JavaScript parsing behavior */
35
parse?: ParseOptions;
36
/** Support for Safari 10 compatibility */
37
safari10?: boolean;
38
/** Enable/configure source map generation */
39
sourceMap?: boolean | SourceMapOptions;
40
/** Process variables in top-level scope */
41
toplevel?: boolean;
42
}
43
```
44
45
### Parse Options
46
47
Controls JavaScript parsing behavior and syntax support.
48
49
```typescript { .api }
50
interface ParseOptions {
51
/** Allow return statements outside functions */
52
bare_returns?: boolean;
53
/** @deprecated ECMAScript version (all supported versions are valid) */
54
ecma?: ECMA;
55
/** Support HTML5-style comments */
56
html5_comments?: boolean;
57
/** Preserve Unix shebang lines */
58
shebang?: boolean;
59
}
60
```
61
62
**Usage Examples:**
63
64
```typescript
65
const parseOptions: ParseOptions = {
66
bare_returns: true, // For CommonJS modules
67
html5_comments: true, // Support <!-- comments -->
68
shebang: true // Preserve #!/usr/bin/env node
69
};
70
71
await minify(code, { parse: parseOptions });
72
```
73
74
### Compression Options
75
76
Extensive optimization configuration with 75+ individual settings for dead code elimination, constant folding, and advanced transformations.
77
78
```typescript { .api }
79
interface CompressOptions {
80
/** Optimize function arguments */
81
arguments?: boolean;
82
/** Convert function expressions to arrow functions */
83
arrows?: boolean;
84
/** Represent booleans as integers */
85
booleans_as_integers?: boolean;
86
/** Optimize boolean expressions */
87
booleans?: boolean;
88
/** Collapse single-use variables */
89
collapse_vars?: boolean;
90
/** Optimize comparison operations */
91
comparisons?: boolean;
92
/** Optimize computed property access */
93
computed_props?: boolean;
94
/** Optimize conditional expressions */
95
conditionals?: boolean;
96
/** Remove unreachable code */
97
dead_code?: boolean;
98
/** Apply default optimizations */
99
defaults?: boolean;
100
/** Process directive prologues */
101
directives?: boolean;
102
/** Remove console.* calls */
103
drop_console?: boolean | ConsoleProperty[];
104
/** Remove debugger statements */
105
drop_debugger?: boolean;
106
/** Target ECMAScript version */
107
ecma?: ECMA;
108
/** Evaluate constant expressions */
109
evaluate?: boolean;
110
/** Parse input as single expression */
111
expression?: boolean;
112
/** Define global constants */
113
global_defs?: object;
114
/** Hoist function declarations */
115
hoist_funs?: boolean;
116
/** Hoist property assignments */
117
hoist_props?: boolean;
118
/** Hoist var declarations */
119
hoist_vars?: boolean;
120
/** Support IE8 compatibility */
121
ie8?: boolean;
122
/** Optimize return statements in if blocks */
123
if_return?: boolean;
124
/** Inline function calls */
125
inline?: boolean | InlineFunctions;
126
/** Join consecutive var statements */
127
join_vars?: boolean;
128
/** Preserve class names */
129
keep_classnames?: boolean | RegExp;
130
/** Preserve function arguments in unused functions */
131
keep_fargs?: boolean;
132
/** Preserve function names */
133
keep_fnames?: boolean | RegExp;
134
/** Keep Infinity literal */
135
keep_infinity?: boolean;
136
/** Optimize left-hand side constants */
137
lhs_constants?: boolean;
138
/** Optimize loop structures */
139
loops?: boolean;
140
/** Treat input as module */
141
module?: boolean;
142
/** Negate immediately invoked function expressions */
143
negate_iife?: boolean;
144
/** Number of compression passes */
145
passes?: number;
146
/** Optimize property access */
147
properties?: boolean;
148
/** Functions safe to remove when return value unused */
149
pure_funcs?: string[];
150
/** Constructors safe to remove when return value unused */
151
pure_new?: boolean;
152
/** Property getters with no side effects */
153
pure_getters?: boolean | 'strict';
154
/** Inline and remove function declarations */
155
reduce_funcs?: boolean;
156
/** Optimize variable assignments and usage */
157
reduce_vars?: boolean;
158
/** Join consecutive statements with comma operator */
159
sequences?: boolean | number;
160
/** Drop side-effect-free statements */
161
side_effects?: boolean;
162
/** Optimize switch statements */
163
switches?: boolean;
164
/** Process top-level scope */
165
toplevel?: boolean;
166
/** Names to preserve in top-level scope */
167
top_retain?: null | string | string[] | RegExp;
168
/** Optimize typeof expressions */
169
typeofs?: boolean;
170
/** Convert functions to arrow functions (unsafe) */
171
unsafe_arrows?: boolean;
172
/** Enable unsafe optimizations */
173
unsafe?: boolean;
174
/** Unsafe comparison optimizations */
175
unsafe_comps?: boolean;
176
/** Optimize Function constructor calls */
177
unsafe_Function?: boolean;
178
/** Optimize Math.* calls */
179
unsafe_math?: boolean;
180
/** Optimize symbol operations */
181
unsafe_symbols?: boolean;
182
/** Optimize method calls */
183
unsafe_methods?: boolean;
184
/** Optimize prototype operations */
185
unsafe_proto?: boolean;
186
/** Optimize regular expression literals */
187
unsafe_regexp?: boolean;
188
/** Optimize undefined comparisons */
189
unsafe_undefined?: boolean;
190
/** Remove unused variables and functions */
191
unused?: boolean;
192
}
193
```
194
195
[Compression](./compression.md)
196
197
### Name Mangling
198
199
Variable, function, and property name obfuscation system with customizable identifier generation and preservation rules.
200
201
```typescript { .api }
202
interface MangleOptions {
203
/** Mangle names in eval scope */
204
eval?: boolean;
205
/** Preserve class names */
206
keep_classnames?: boolean | RegExp;
207
/** Preserve function names */
208
keep_fnames?: boolean | RegExp;
209
/** Treat input as module */
210
module?: boolean;
211
/** Custom identifier generation algorithm */
212
nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler;
213
/** Enable/configure property name mangling */
214
properties?: boolean | ManglePropertiesOptions;
215
/** Names to exclude from mangling */
216
reserved?: string[];
217
/** Safari 10 compatibility mode */
218
safari10?: boolean;
219
/** Process top-level scope */
220
toplevel?: boolean;
221
}
222
```
223
224
[Name Mangling](./mangling.md)
225
226
### Output Formatting
227
228
Code generation and formatting configuration controlling whitespace, comments, quotes, and structural formatting.
229
230
```typescript { .api }
231
interface FormatOptions {
232
/** Use ASCII-only output */
233
ascii_only?: boolean;
234
/** @deprecated Not implemented */
235
beautify?: boolean;
236
/** Always use braces for control structures */
237
braces?: boolean;
238
/** Comment preservation configuration */
239
comments?: boolean | 'all' | 'some' | RegExp | ((node: any, comment: CommentObject) => boolean);
240
/** Target ECMAScript version */
241
ecma?: ECMA;
242
/** IE8 compatibility mode */
243
ie8?: boolean;
244
/** Preserve numeric literals */
245
keep_numbers?: boolean;
246
/** Indentation level */
247
indent_level?: number;
248
/** Starting indentation */
249
indent_start?: number;
250
/** Inline script tag compatibility */
251
inline_script?: boolean;
252
/** Keep quoted property names */
253
keep_quoted_props?: boolean;
254
/** Maximum line length */
255
max_line_len?: number | false;
256
/** Code preamble */
257
preamble?: string;
258
/** Preserve type annotations */
259
preserve_annotations?: boolean;
260
/** Quote all property keys */
261
quote_keys?: boolean;
262
/** Quote style preference */
263
quote_style?: OutputQuoteStyle;
264
/** Safari 10 compatibility */
265
safari10?: boolean;
266
/** Use semicolons */
267
semicolons?: boolean;
268
/** Preserve shebang */
269
shebang?: boolean;
270
/** Use shorthand properties */
271
shorthand?: boolean;
272
/** Source map configuration */
273
source_map?: SourceMapOptions;
274
/** WebKit compatibility mode */
275
webkit?: boolean;
276
/** Output width for beautification */
277
width?: number;
278
/** Wrap IIFEs in parentheses */
279
wrap_iife?: boolean;
280
/** Wrap function arguments in parentheses */
281
wrap_func_args?: boolean;
282
}
283
284
interface CommentObject {
285
value: string;
286
type: 'comment1' | 'comment2' | 'comment3' | 'comment4';
287
pos: number;
288
line: number;
289
col: number;
290
}
291
```
292
293
[Output Formatting](./formatting.md)
294
295
## Types
296
297
```typescript { .api }
298
interface MinifyOutput {
299
/** The minified JavaScript code */
300
code?: string;
301
/** Source map as JSON string */
302
map?: string;
303
/** Decoded source map object for programmatic access */
304
decoded_map?: object | null;
305
/** Performance timing information (when timings: true) */
306
timings?: {
307
parse: number;
308
rename: number;
309
compress: number;
310
scope: number;
311
mangle: number;
312
properties: number;
313
format: number;
314
total: number;
315
};
316
}
317
318
type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
319
320
type ConsoleProperty = keyof typeof console;
321
type DropConsoleOption = boolean | ConsoleProperty[];
322
323
enum InlineFunctions {
324
Disabled = 0,
325
SimpleFunctions = 1,
326
WithArguments = 2,
327
WithArgumentsAndVariables = 3
328
}
329
330
enum OutputQuoteStyle {
331
PreferDouble = 0,
332
AlwaysSingle = 1,
333
AlwaysDouble = 2,
334
AlwaysOriginal = 3
335
}
336
```