DeployEdit this page.md

Bun

To deploy as a standalone Bun server, use the built-in bun adapter. This adapter uses Bun's native Bun.serve() API with edge-compatible fetch handlers and zero-copy static file serving.

You need Bun installed on your system:

curl -fsSL https://bun.sh/install | bash

No additional packages are needed - the adapter is built into @lazarv/react-server.

When you run a production build with Bun, the bun adapter is automatically detected and used — no configuration is needed. If you want to be explicit or need to pass options, you can add the adapter to your react-server.config.mjs file:

export default { adapter: "bun", };

You can customize the adapter by passing options:

export default { adapter: [ "bun", { name: "my-app", // Application name (used in generated package.json) }, ], };

Configuration Options

Environment Variables

The generated server supports the following environment variables at runtime:

The Bun adapter uses an edge build mode, bundling your entire server into a single file. At build time, it:

  1. Bundles your server code into .bun/server/.react-server/server/edge.mjs
  2. Copies all static assets into .bun/static/
  3. Generates a start.mjs script with a build-time static route map that uses Bun.serve({ static }) for zero-copy static file serving
  4. Creates a package.json for easy deployment

Static files (HTML, CSS, JS, images, etc.) are served directly by Bun's optimized static file handling without going through the fetch handler, giving you the best possible performance for static assets.

Build your application using the react-server CLI:

pnpm react-server build [root]

This produces a .bun/ directory with the following structure:

.bun/ ├── start.mjs # Entry point with static route map ├── package.json # Deployment metadata ├── static/ # All static assets │ ├── assets/ # Hashed build assets (CSS, JS) │ ├── client/ # Client-side bundles │ └── ... # Public files, pre-rendered HTML └── server/ └── .react-server/ └── server/ └── edge.mjs # Bundled server

Start the production server using the CLI:

bun --bun react-server start

Or run it directly without the runtime installed:

bun --bun .bun/start.mjs

Or use the --deploy flag to build and immediately start:

pnpm react-server build [root] --deploy

You can also use the generated package.json scripts:

cd .bun bun start

Since the Bun adapter produces a self-contained server, you can deploy it anywhere Bun runs:

Example Dockerfile

FROM oven/bun:latest WORKDIR /app COPY .bun/ . EXPOSE 3000 CMD ["bun", "start.mjs"]