Visitar URL original
Compiler | Bun Docs

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
./mycli
Hello world!

Two ways to compile#

bun build --compilebun compile
The executable holdsYour bundled JavaScriptMachine code
It runsWith the JIT, like bun runWithout a JIT
TypeScript typesRemoved, never checkedChecked, then used
Builds forAny platform, with --targetThe platform you build on
StatusStableExperimental

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.