Reduce bundle size and improve startup time with Bun’s fast JavaScript and TypeScript minifier. Supports whitespace removal, syntax optimization, identifier shortening, and bytecode compilation.
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.
Renames local variables and function names to shorter identifiers using frequency-based optimization. The most-used identifiers get the shortest names.
function calculateSum(firstNumber: number, secondNumber: number) { const result = firstNumber + secondNumber; return result;}
Named exports, exports, module, JavaScript keywords, and global identifiers are never renamed.
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.
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.