Compiler
Turn a TypeScript or JavaScript program into one executable file
Bun turns a TypeScript or JavaScript program into one executable file. It runs on machines that don't have Bun installed.
cli.ts
console.log("Hello world!");terminal
bun build --compile ./cli.ts --outfile mycli
./mycliHello world!Two ways to compile#
bun build --compile | bun compile | |
|---|---|---|
| The executable holds | Your bundled JavaScript | Machine code |
| It runs | With the JIT, like bun run | Without a JIT |
| TypeScript types | Removed, never checked | Checked, then used |
| Builds for | Any platform, with --target | The platform you build on |
| Status | Stable | Experimental |
bun build --compile runs nearly everything that bun run runs. With bun compile, which is short for bun build --compile --aot, your program starts faster, and a few things differ from bun run. A large application uses less memory, and a tiny program uses about as much as without AoT.
Read next#
- Single-file executable: cross-compile, embed files, sign the executable.
- Bytecode caching: make an executable from
bun build --compilestart faster. - Standalone HTML:
--compile --target=browserwrites one.htmlfile. - Ahead-of-time compilation: what
bun compilegets you, and when to stay with the JIT. - Types and typed percentage: make compiled code faster.
- Compatibility and libraries: what differs from
bun run. - Debugging, size and troubleshooting.