bun build run faster since there’s less code to print. CLI Usage
Enable all minification
Use the--minify flag to enable all minification modes: --minify flag automatically enables: - Whitespace minification
- Syntax minification
- Identifier minification
Production mode
The--production flag automatically enables minification: --production flag also: - Sets
process.env.NODE_ENVtoproduction - Enables the production-mode JSX import & transform
Granular control
You can enable specific minification modes individually:JavaScript API
When using Bun’s bundler programmatically, configure minification through theminify option: Minification Modes
Bun’s minifier has three independent modes that can be enabled separately or combined.Whitespace minification (--minify-whitespace)
Removes all unnecessary whitespace, newlines, and formatting from the output. Syntax minification (--minify-syntax)
Rewrites JavaScript syntax to shorter equivalent forms and performs constant folding, dead code elimination, and other optimizations. Identifier minification (--minify-identifiers)
Renames local variables and function names to shorter identifiers using frequency-based optimization. All Transformations
Boolean literal shortening
Mode:--minify-syntax Converts boolean literals to shorter expressions. Input
Output
Boolean algebra optimizations
Mode:--minify-syntax Simplifies boolean expressions using logical rules. Input
Output
Undefined shortening
Mode:--minify-syntax Replaces undefined with shorter equivalent. Input
Output
Undefined equality optimization
Mode:--minify-syntax Optimizes loose equality checks with undefined. Input
Output
Infinity shortening
Mode:--minify-syntax Converts Infinity to mathematical expressions. Input
Output
Typeof optimizations
Mode:--minify-syntax Optimizes typeof comparisons and evaluates constant typeof expressions. Input
Output
Number formatting
Mode:--minify-syntax Formats numbers in the most compact representation. Input
Output
Arithmetic constant folding
Mode:--minify-syntax Evaluates arithmetic operations at compile time. Input
Output
Bitwise constant folding
Mode:--minify-syntax Evaluates bitwise operations at compile time. Input
Output
String concatenation
Mode:--minify-syntax Combines string literals at compile time. Input
Output
String indexing
Mode:--minify-syntax Evaluates string character access at compile time. Input
Output
Template literal folding
Mode:--minify-syntax Evaluates template literals with constant expressions. Input
Output
Template literal to string conversion
Mode:--minify-syntax Converts simple template literals to regular strings. Input
Output
String quote optimization
Mode:--minify-syntax Chooses the optimal quote character to minimize escapes. Input
Output
Array spread inlining
Mode:--minify-syntax Inlines array spread operations with constant arrays. Input
Output
Array indexing
Mode:--minify-syntax Evaluates constant array access at compile time. Input
Output
Property access optimization
Mode:--minify-syntax Converts bracket notation to dot notation when possible. Input
Output
Comparison folding
Mode:--minify-syntax Evaluates constant comparisons at compile time. Input
Output
Logical operation folding
Mode:--minify-syntax Simplifies logical operations with constant values. Input
Output
Nullish coalescing folding
Mode:--minify-syntax Evaluates nullish coalescing with known values. Input
Output
Comma expression simplification
Mode:--minify-syntax Removes side-effect-free expressions from comma sequences. Input
Output
Ternary conditional folding
Mode:--minify-syntax Evaluates conditional expressions with constant conditions. Input
Output
Unary expression folding
Mode:--minify-syntax Simplifies unary operations. Input
Output
Double negation removal
Mode:--minify-syntax Removes unnecessary double negations. Input
Output
If statement optimization
Mode:--minify-syntax Optimizes if statements with constant conditions. Input
Output
Dead code elimination
Mode:--minify-syntax Removes unreachable code and code without side effects. Input
Output
Unreachable branch removal
Mode:--minify-syntax Removes branches that can never execute. Input
Output
Empty block removal
Mode:--minify-syntax Removes empty blocks and unnecessary braces. Input
Output
Single statement block unwrapping
Mode:--minify-syntax Removes unnecessary braces around single statements. Input
Output
TypeScript enum inlining
Mode:--minify-syntax Inlines TypeScript enum values at compile time. Input
Output
Pure annotation support
Mode: Always active Respects/*@__PURE__*/ annotations for tree shaking. Input
Output
Identifier renaming
Mode:--minify-identifiers Renames local variables to shorter names based on usage frequency. Input
Output
- Most frequently used identifiers get the shortest names (a, b, c…)
- Single letters: a-z (26 names)
- Double letters: aa-zz (676 names)
- Triple letters and beyond as needed
- JavaScript keywords and reserved words
- Global identifiers
- Named exports (to maintain API)
- CommonJS names:
exports,module
Whitespace removal
Mode:--minify-whitespace Removes all unnecessary whitespace. Input
Output
Semicolon optimization
Mode:--minify-whitespace Inserts semicolons only when necessary. Input
Output
Operator spacing removal
Mode:--minify-whitespace Removes spaces around operators. Input
Output
Comment removal
Mode:--minify-whitespace Removes comments except important license comments. Input
Output
Object and array formatting
Mode:--minify-whitespace Removes whitespace in object and array literals. Input
Output
Control flow formatting
Mode:--minify-whitespace Removes whitespace in control structures. Input
Output
Function formatting
Mode:--minify-whitespace Removes whitespace in function declarations. Input
Output
Parentheses minimization
Mode: Always active Only adds parentheses when necessary for operator precedence.Input
Output
Property mangling
Mode:--minify-identifiers (with configuration) Renames object properties to shorter names when configured. Input
Output (with property mangling enabled)
Template literal value folding
Mode:--minify-syntax Converts non-string interpolated values to strings and folds them into the template. Input
Output
String length constant folding
Mode:--minify-syntax Evaluates .length property on string literals at compile time. Input
Output
Constructor call simplification
Mode:--minify-syntax Simplifies constructor calls for built-in types. Input
Output
Single property object inlining
Mode:--minify-syntax Inlines property access for objects with a single property. Input
Output
String charCodeAt constant folding
Mode: Always active EvaluatescharCodeAt() on string literals for ASCII characters. Input
Output
Void 0 equality to null equality
Mode:--minify-syntax Converts loose equality checks with void 0 to null since they’re equivalent. Input
Output
Negation operator optimization
Mode:--minify-syntax Moves negation operator through comma expressions. Input
Output
Import.meta property inlining
Mode: Bundle mode Inlinesimport.meta properties at build time when values are known. Input
Output
Variable declaration merging
Mode:--minify-syntax Merges adjacent variable declarations of the same type. Input
Output
Expression statement merging
Mode:--minify-syntax Merges adjacent expression statements using comma operator. Input
Output
Return statement merging
Mode:--minify-syntax Merges expressions before return with comma operator. Input
Output
Throw statement merging
Mode:--minify-syntax Merges expressions before throw with comma operator. Input
Output
TypeScript enum cross-module inlining
Mode:--minify-syntax (bundle mode) Inlines enum values across module boundaries. Input
Output
Computed property enum inlining
Mode:--minify-syntax Inlines enum values used as computed object properties. Input
Output
String number to numeric index
Mode:--minify-syntax Converts string numeric property access to numeric index. Input
Output
Arrow function body shortening
Mode: Always active Uses expression body syntax when an arrow function only returns a value.Input
Output
Object property shorthand
Mode: Always active Uses shorthand syntax when property name and value identifier match.Input
Output
Method shorthand
Mode: Always active Uses method shorthand syntax in object literals.Input
Output
Drop debugger statements
Mode:--drop=debugger Removes debugger statements from code. Input
Output
Drop console calls
Mode:--drop=console Removes all console.* method calls from code. Input
Output
Drop custom function calls
Mode:--drop=<name> Removes calls to specified global functions or methods. Input
Output with --drop=assert
Keep Names
When minifying identifiers, you may want to preserve original function and class names for debugging purposes. Use the--keep-names flag: .name property on functions and classes while still minifying the actual identifier names in the code. Combined Example
Using all three minification modes together:input.ts (158 bytes)
output.js
When to Use Minification
Use--minify for: - Production bundles
- Reducing CDN bandwidth costs
- Improving page load times
--minify-whitespace: Quick size reduction without semantic changes--minify-syntax: Smaller output while keeping readable identifiers for debugging--minify-identifiers: Maximum size reduction (combine with--keep-namesfor better stack traces)
- Development builds (harder to debug)
- When you need readable error messages
- Libraries where consumers may read the source