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. ption value='cf-user-defined-entryfile'>cf-user-defined-entryfile Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/.github/workflows/nodejs.yml (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2021-05-03Attempt to fix CI skipping (#165)Gravatar Drew Powers 1-0/+1
2021-05-03chore: release create-astro@0.1.0Gravatar Nate Moore 3-8/+9
2021-05-03`create-astro` UI (#164)Gravatar Nate Moore 44-1700/+2871
2021-05-01Improve esbuild watch mode (#160)Gravatar Drew Powers 1-38/+49
2021-04-30fix: monorepo issues (#158)Gravatar Nate Moore 4-252/+195
2021-04-30Migrate to `yarn` monorepo (#157)Gravatar Nate Moore 269-37696/+12780
2021-04-30Fix RSS dategen (#156)Gravatar Drew Powers 3-6/+7
2021-04-30Add portfolio example (#140)Gravatar Drew Powers 22-5/+907
2021-04-30chore: release 0.0.9Gravatar Nate Moore 1-1/+1
2021-04-30Fix Svelte bundled behavior (#151)Gravatar Nate Moore 6-46/+59
2021-04-30fix: typoGravatar Nate Moore 1-1/+1
2021-04-30chore fix tests (#149)Gravatar duncanhealy 2-3/+3
2021-04-29chore: update to snowpack@3.3.7 (#150)Gravatar Nate Moore 3-78/+34
2021-04-29build: add warning if no public folder found #96 (#144)Gravatar duncanhealy 1-1/+4
2021-04-29fix: @vue/server-renderer tree-shaking (#148)Gravatar Nate Moore 1-0/+3
2021-04-29Remove .DS_Store files (#146)Gravatar Nate Moore 5-1/+1
2021-04-29chore: add _site, mac file to gitignore (#147)Gravatar duncanhealy 1-0/+2
2021-04-29example blog add buildoptions (#142)Gravatar duncanhealy 1-1/+8