Skip to main content
The --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.
Run the output binary directly:
All imported files and npm packages are bundled into the executable, along with a copy of the Bun runtime. All built-in Bun and Node.js APIs are available.

Cross-compilation

Use --target to compile for a different OS or architecture than your current machine.

Linux

Windows

macOS

Supported targets

On x64 platforms, the modern build requires CPUs that support AVX2 instructions (Intel Haswell / 2013+). Use the -baseline target for older hardware. If you see "Illegal instruction" errors, switch to -baseline.

Production deployment

For production binaries, combine minification, sourcemaps, and bytecode:
  • --minify reduces the size of bundled code
  • --sourcemap embeds a sourcemap (compressed with zstd) so stack traces point to original source
  • --bytecode pre-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:
The resulting binary contains your server code, the Bun runtime, all frontend assets (HTML, CSS, JS), and every npm dependency. Deploy it anywhere — no installation needed.

Embedding assets

Use the with { type: "file" } import attribute to embed files into the executable:
At runtime, the import returns an internal path (prefixed $bunfs/) that Bun.file() and Node.js fs APIs can read.

Serving static assets

Embedding a SQLite database

The database is embedded read-write but changes are lost when the process exits.

Listing embedded files

Embed directories

Build-time constants

Use --define to inject values at compile time:

Workers

To use Worker in a standalone executable, include the worker’s entrypoint in the build:
index.ts

Windows-specific options

Windows-specific flags cannot be used when cross-compiling from a non-Windows machine.

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

Usage forms:

Limitations

The --compile flag does not support:
  • --outdir (use outfile instead, except when combined with --splitting)
  • --public-path
  • --target=node
  • --no-bundle