Bun includes a fast JavaScript and TypeScript minifier that can reduce bundle sizes by 80% or more. It performs constant folding, dead code elimination, syntax transformations, and identifier shortening. Because Bun minifies during bundling (not as a separate pass), there is less code to print — makingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/oven-sh/bun/llms.txt
Use this file to discover all available pages before exploring further.
bun build faster than running an external minifier.
Enabling minification
Use--minify to enable all minification modes at once:
- CLI
- JavaScript API
--minify enables all three modes: whitespace removal, syntax optimization, and identifier shortening.
Production mode
The--production flag also enables full minification:
--production additionally sets process.env.NODE_ENV to "production" and enables the production JSX transform.
Granular control
Enable individual modes separately:- CLI
- JavaScript API
Minification modes
--minify-whitespace
Removes all unnecessary whitespace, newlines, comments, and formatting.
/*! ... */) are preserved.
--minify-syntax
Rewrites JavaScript syntax to shorter equivalent forms. Performs constant folding, dead code elimination, and dozens of other optimizations.
--minify-identifiers
Renames local variables and function names to shorter identifiers using frequency-based optimization. The most-used identifiers get the shortest names.
exports, module, JavaScript keywords, and global identifiers are never renamed.
Combined example
Using all three modes together:Syntax transformations reference
Boolean and logical simplification
Boolean and logical simplification
Constant folding — arithmetic
Constant folding — arithmetic
Constant folding — strings
Constant folding — strings
Dead code elimination
Dead code elimination
Undefined and Infinity shortening
Undefined and Infinity shortening
Typeof optimizations
Typeof optimizations
Number formatting
Number formatting
TypeScript enum inlining
TypeScript enum inlining
Variable declaration merging
Variable declaration merging
If statement optimization
If statement optimization
Source maps with minification
Always use source maps in production so that error stack traces point to original source:- CLI
- JavaScript API
Bytecode compilation
Combine minification with--bytecode to also reduce startup time:
- CLI
- JavaScript API
.jsc file alongside each .js bundle. Bun automatically uses it at runtime:
Bytecode is not portable across Bun versions. The
.jsc file is tied to the JavaScriptCore version embedded in the Bun binary. Regenerate bytecode after updating Bun.Keep names
When minifying identifiers, preserve original function and class names for better stack traces:- CLI
- JavaScript API
.name property on functions and classes while still shortening identifier names in the code.
Drop specific calls
Removeconsole.* calls or debugger statements from production builds:
- CLI
- JavaScript API
When to use each mode
--minify-whitespace
Quick size reduction without any semantic changes. Safe to use on its own without full syntax minification.
--minify-syntax
Smaller output while keeping readable identifier names. Good for debugging production issues.
--minify-identifiers
Maximum compression. Combine with
--keep-names for better stack traces.Avoid minification for development builds — it makes errors harder to debug and provides no benefit during development.