# Bun executable

`--preset bun-compile` builds the app as one executable at `.output/app`: the Bun runtime, the server and every public file in a single file you copy to a host that has nothing installed. It has no detection; name it with `--preset` or `preset`.

## Reference

|                      |                             |
| -------------------- | --------------------------- |
| Preset               | `bun-compile`               |
| Runs on              | any host that runs a binary |
| `event.runtime.name` | `bun`                       |
| Server target        | `bun`                       |
| Lifetime, startup    | `process`, `load`           |

### Output

```text
.output/
  hamur.json
  <name>                     the executable: the Bun runtime, the server and every public file (<name>.exe for a bun-windows-* target)
  public/                    still written, so a CDN can serve it
```

### Config keys

| Key                 | Default           | What it does                                              |
| ------------------- | ----------------- | --------------------------------------------------------- |
| `bunCompile.name`   | `"app"`           | the file name below `.output/`                            |
| `bunCompile.target` | the build machine | any `Bun.Build.CompileTarget`, such as `bun-linux-x64`    |
| `build.bytecode`    | `false`           | add Bun bytecode of the server to the executable          |
| `server.https`      | unset             | as on `bun`; env `HAMUR_SSL_KEY` and `HAMUR_SSL_CERT` win |
| `server.unix`       | unset             | as on `bun`; env `HAMUR_UNIX_SOCKET` wins                 |

### Detection

None. Name it with `--preset`, `preset` in the config or `HAMUR_PRESET`; no environment variable selects it.

### Deploy command

No `hamur deploy` command: it exits 1 for this preset. Copy `.output/<name>` to the host and run it. `hamur preview` runs it. The preview command of the preset, which `hamur preview` runs or prints, is `.output/app`.

### Limits

- Runs: WebSockets and `server.syncedState`, `server.pubsub`, streamed answers, `server.metrics`, image transforms at run time, private `app/env.ts` entries read at run time.
- Does not run: Durable Object classes.
- `build.external` and `build.serverBundles` fail the build; the default `data` and `session` mounts are in memory; `bun-compile` reads no `.env`, `bunfig.toml` or `tsconfig.json` at run time.
- `scheduledTasks` run in process in UTC, `tasks.runOnStart` runs, and `tasks.queue` does not apply (`enqueue` runs the task in process, not durably). The request body limit is `server.maxRequestBodySize`, 128 MiB.

The levels are the `features` of the preset: `hamur build` warns or fails when the app uses a feature the preset does not run (see [Preset features](/deploy#preset-features)).

```ts
export default defineConfig({ preset: "bun-compile", bunCompile: { target: "bun-linux-x64", name: "site" } })
```

`bunCompile.target` is any `Bun.Build.CompileTarget` (`bun-linux-x64`, `bun-linux-arm64-musl`, `bun-darwin-arm64`, `bun-windows-x64`, and the `-baseline` and `-modern` forms); unset it is the machine that builds, and another target makes Bun download that platform's runtime. `bunCompile.name` is the file name below `.output/` (default `app`, and `.exe` is added for a `bun-windows-*` target). A target that is not one of Bun's fails the load: `bunCompile.target "bun-linux" is not a Bun compile target`.

`build.bytecode: true` (default `false`) adds Bun bytecode of the server to the executable. It needs this preset, since Bun writes ESM bytecode only into a compiled executable; any other preset fails with `build.bytecode needs the bun-compile preset: Bun writes ESM bytecode only into a compiled executable`.

The executable starts the server whenever it runs: it listens on `PORT` (default 3000) and `HOST`, drains on `SIGTERM` and `SIGINT`, and reads `HAMUR_SSL_KEY`, `HAMUR_SSL_CERT` and `HAMUR_UNIX_SOCKET` (or `server.https` and `server.unix`) as the [bun server](/deploy/presets/bun#https-and-unix-sockets) does. `hamur preview` runs it.

- **Nothing is read from the directory it runs in.** It loads no `.env`, `bunfig.toml` or `tsconfig.json`; its environment is the host's.
- **Public files are inside it.** `.output/public/` (the `.gz`, `.br` and `.zst` copies and the prerendered pages too) is embedded and answered with the same strong ETags, ranges and `Accept-Encoding` choice as on `bun`. `.output/public/` is still written, so you can serve it from a CDN.
- **No `build.external`.** A package that is not bundled is not in the file: `build.external "pg-native" cannot run in a bun-compile executable: it is not embedded`. `build.serverBundles` fails too, because the executable is one file.
- **No default `fs` storage.** The default `data` and `session` mounts are in memory, since the file's own folder is read-only; configure a `storage` mount with a path on the host.
- **Server assets are inlined** whatever their size, and an `isr` route starts from its first render, not from a build-time seed.
