Bun's bundler implements a `--compile` flag for generating a standalone binary from a TypeScript or JavaScript file. {% codetabs %} ```bash $ bun build ./cli.ts --compile --outfile mycli ``` ```ts#cli.ts console.log("Hello world!"); ``` {% /codetabs %} This bundles `cli.ts` into an executable that can be executed directly: ``` $ ./mycli Hello world! ``` All imported files and packages are bundled into the executable, along with a copy of the Bun runtime. All built-in Bun and Node.js APIs are supported. {% callout %} **Note** — Currently, the `--compile` flag can only accept a single entrypoint at a time and does not support the following flags: - `--outdir` — use `outfile` instead. - `--external` - `--splitting` - `--public-path` {% /callout %} ## Embedding files Standalone executables support embedding files. To embed files into an executable with `bun build --compile`, import the file in your code ```js // this becomes an internal file path import icon from "./icon.png"; import { file } from "bun"; export default { fetch(req) { return new Response(file(icon)); }, }; ``` You may need to specify a `--loader` for it to be treated as a `"file"` loader (so you get back a file path). Embedded files can be read using `Bun.file`'s functions or the Node.js `fs.readFile` function (in `"node:fs"`). ## Minification To trim down the size of the executable a little, pass `--minify` to `bun build --compile`. This uses Bun's minifier to reduce the code size. Overall though, Bun's binary is still way too big and we need to make it smaller. test-command'>ciro/fix-test-command Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/ffi.test.fixture.callback.c (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-06-22Update WebKitGravatar Jarred Sumner 1-0/+0
2022-06-22cleanup websocket testGravatar Jarred Sumner 1-3/+6
2022-06-22Fix `WebSocket` when HTTP server is not runningGravatar Jarred Sumner 14-38/+103
2022-06-22Update build-idGravatar Jarred Sumner 1-1/+1
2022-06-22cleanupGravatar Jarred Sumner 6-719/+3
2022-06-22Update index.d.tsGravatar Jarred Sumner 1-0/+1
2022-06-22types for `bun:jsc`Gravatar Jarred Sumner 2-1/+37
2022-06-22Slightly customize the `events` polyfill so it uses ESMGravatar Jarred Sumner 1-1/+522
2022-06-22Fix memory bugs in escapeHTML & arrayBufferToStringGravatar Jarred Sumner 1-65/+61