Skip to main content
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 — making bun build faster than running an external minifier.

Enabling minification

Use --minify to enable all minification modes at once:
--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:

Minification modes

--minify-whitespace

Removes all unnecessary whitespace, newlines, comments, and formatting.
License comments (/*! ... */) 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.
Named exports, exports, module, JavaScript keywords, and global identifiers are never renamed.

Combined example

Using all three modes together:

Syntax transformations reference

Source maps with minification

Always use source maps in production so that error stack traces point to original source:
See Bundler Overview — sourcemaps for all sourcemap options.

Bytecode compilation

Combine minification with --bytecode to also reduce startup time:
Bytecode pre-compiles JavaScript to JavaScriptCore bytecode at build time, moving parsing overhead out of the critical startup path. Typical improvement: 1.5–4x faster startup depending on application size. Bytecode caching generates a .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:
This preserves the .name property on functions and classes while still shortening identifier names in the code.

Drop specific calls

Remove console.* calls or debugger statements from production builds:
You can also drop custom function calls by name:

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.
For production CLI tools and long-running servers, use --minify --sourcemap=linked --bytecode together for the best combination of small output and fast startup.
Avoid minification for development builds — it makes errors harder to debug and provides no benefit during development.