svelte-bun-compile
v0.1.0
Published
Compile your SvelteKit app into a Bun single-file executable
Maintainers
Readme
svelte-bun-compile
Compile your SvelteKit app into a Bun single-file executable.
Sibling of next-bun-compile.
Your whole app — server, client assets, prerendered pages — becomes one
self-contained binary. No node_modules on the server, no runtime to
install, static assets served from memory with automatic ETags. Ship it
with scp, run it with systemd, or deploy it with
Homeport.
Usage
bun add -d svelte-bun-compile// svelte.config.js
import adapter from 'svelte-bun-compile';
/** @type {import('@sveltejs/kit').Config} */
export default {
kit: {
adapter: adapter()
}
};Build with the Bun runtime (the adapter uses Bun.build to compile):
bun --bun vite build
./dist/app # → Listening on http://localhost:3000Options
adapter({
out: 'dist', // output directory
binaryName: 'app', // binary filename (.exe appended on Windows)
target: 'bun-linux-x64', // cross-compile target; omit for current platform
bun: { // Bun.build overrides, merged over production defaults
// defaults: minify, bytecode, linked sourcemap, NODE_ENV=production
}
});Cross-compile targets: bun-linux-x64, bun-linux-arm64, bun-darwin-arm64,
bun-windows-x64, and friends — build on macOS, deploy to Linux.
What the binary does
- Static & prerendered routes from memory via Bun's static route dispatch:
automatic ETag +
If-None-Match→ 304, immutable cache headers for/_app/immutable/*, zero-allocation matching. - Pretty URLs for prerendered pages (
/aboutand/about.htmlshare one in-memory response) and prerendered redirects served without touching SSR. - SSR for everything else through SvelteKit's server, including
read()from$app/server— server assets are embedded too. - Reverse-proxy aware — same env contract as
adapter-node:ORIGIN,PROTOCOL_HEADER,HOST_HEADER,PORT_HEADER,ADDRESS_HEADER,XFF_DEPTH. - Graceful shutdown on SIGINT/SIGTERM: stops accepting connections,
gives in-flight requests
SHUTDOWN_TIMEOUTseconds (default 30), emitssveltekit:shutdown.
Runtime environment
| Variable | Default | |
|---|---|---|
| PORT | 3000 | listen port |
| HOST | 0.0.0.0 | bind address |
| ORIGIN | — | canonical origin behind a proxy |
| PROTOCOL_HEADER / HOST_HEADER / PORT_HEADER | — | forwarded-URL reconstruction |
| ADDRESS_HEADER, XFF_DEPTH | —, 1 | client IP behind proxies |
| SHUTDOWN_TIMEOUT | 30 | seconds before in-flight requests are force-closed |
| BUN_IDLE_TIMEOUT | 255 | socket idle timeout (seconds) |
Requirements
- Bun ≥ 1.2 to build (
bun --bun vite build) — the compiled binary itself needs nothing. - SvelteKit 2.
License
MIT
