josephlozano.dev

Compiling a TanStack Start project into a single binary

1/15/2025
tools
  1. Make sure that you are using React 19 or later in your project: bun add react@19.
  2. Modify your app.config.js to add the options from the snippet below.
    • preset: "bun" Tells Nitro that we will be using Bun to run the server.
    • inlineDynamicImports: true Tells Nitro to not to chunk the code.
    • serveStatic: "inline" Tells Nitro to serve static files inline.
  3. Run bun run build to build the project. This will create a .output directory with the compiled code.
  4. Run bun build .output/server/index.js --compile to compile the server into a single binary.

This should also work for other frameworks that use Nitro (such as SolidStart, Nuxt, Vinxi etc).

// app.config.js
import { defineConfig } from "@tanstack/start/config";

export default defineConfig({
  server: {
    preset: "bun",
    inlineDynamicImports: true,
    serveStatic: "inline",
  },
});

Congratulations! You have now compiled a TanStack Start project into a single binary.

← Back to home