--compile flag bundles your code and embeds the Bun runtime into a single executable binary. The resulting file runs without requiring Node.js, Bun, or any npm packages to be installed.
- CLI
- JavaScript API
Cross-compilation
Use--target to compile for a different OS or architecture than your current machine.
Linux
- CLI
- JavaScript API
Windows
- CLI
- JavaScript API
macOS
- CLI
- JavaScript API
Supported targets
Production deployment
For production binaries, combine minification, sourcemaps, and bytecode:- CLI
- JavaScript API
--minifyreduces the size of bundled code--sourcemapembeds a sourcemap (compressed with zstd) so stack traces point to original source--bytecodepre-compiles JavaScript to bytecode, reducing startup time by 2x for large apps
Full-stack executables
When your server code imports an HTML file, Bun bundles both the server and all frontend assets into a single binary:Embedding assets
Use thewith { type: "file" } import attribute to embed files into the executable:
$bunfs/) that Bun.file() and Node.js fs APIs can read.
Serving static assets
Embedding a SQLite database
Listing embedded files
Embed directories
- CLI
- JavaScript API
Build-time constants
Use--define to inject values at compile time:
- CLI
- JavaScript API
Workers
To useWorker in a standalone executable, include the worker’s entrypoint in the build:
- CLI
- JavaScript API
index.ts
Windows-specific options
- CLI
- JavaScript API
macOS code signing
Fix Gatekeeper warnings by codesigning your binary:entitlements.plist
Runtime flags via BUN_OPTIONS
Pass runtime flags to a compiled executable without recompiling:
compile API reference
Limitations
The--compile flag does not support:
--outdir(useoutfileinstead, except when combined with--splitting)--public-path--target=node--no-bundle