Skip to content

@kiln-js/adapter-vercel

@kiln-js/adapter-vercel converts a finished Kiln build into Vercel's Build Output API format. Static files go to Vercel's CDN, and the server runs as one Edge function. The adapter is used by kiln build --target vercel. You can also call it yourself from a build script.

bash
bun add -d @kiln-js/adapter-vercel

What it produces

Running the adapter writes .vercel/output inside the project root:

text
.vercel/output/
  config.json                         Routing and headers for Vercel.
  static/                             Everything from the client build.
    assets/…                          Hashed JS and CSS.
    .vite/manifest.json               The Vite manifest.
  functions/index.func/
    index.js                          The server bundle, minified, for the Edge runtime.
    .vc-config.json                   { "runtime": "edge", "entrypoint": "index.js" }

Deploy the result with the Vercel CLI:

bash
vercel deploy --prebuilt

adaptVercel(options)

ts
import { adaptVercel } from "@kiln-js/adapter-vercel";

await adaptVercel({
  root: process.cwd(),
  clientOut: "dist/client",
  serverOut: "dist/server",
  clientRel: "app/client.tsx",
  bundler: "bun",
});

Options

ts
interface VercelAdapterOptions {
  root: string;       // project root
  clientOut: string;  // folder containing the client build and its manifest
  serverOut: string;  // folder containing server.js
  clientRel: string;  // the client entry's path relative to root, as the manifest keys it
  bundler?: "bun" | "esbuild";  // default "esbuild"
}

clientRel must match a key in the Vite manifest. Otherwise the adapter throws No manifest entry for ….

Steps

The adapter does six things, in order:

  1. Deletes any previous .vercel/output.
  2. Copies the client build into static/.
  3. Reads the manifest and builds the list of stylesheet links and the entry script URL.
  4. Writes a small Edge entry file to .kiln/vercel-entry.ts. It imports the server bundle and calls createHandler with the asset list.
  5. Bundles that entry into functions/index.func/index.js. The bundle targets the browser platform with ES2022, minified, and process.env.NODE_ENV set to production.
  6. Writes config.json, which describes routing.

Bundlers

  • "bun" uses Bun.build when the adapter runs under Bun. If Bun is not the running runtime, it uses esbuild.
  • "esbuild" always uses esbuild.

The CLI picks bun when it runs under Bun and esbuild otherwise.


Routing

config.json is written with these routes, in this order:

  1. handle: "filesystem": serve a static file when one exists at the path.
  2. Any rewrites from vercel.json.
  3. /(.*) to /index: everything else goes to the Edge function.

Headers and redirects from vercel.json are copied into the config as written.

vercel.json

The adapter reads an optional vercel.json at the project root. It supports:

KeyEffect
headersCopied to config.json.
redirectsCopied to config.json.
rewritesConverted to Vercel routes, placed before the Kiln catch-all. Each rewrite is { source, destination }.
cleanUrlsCopied when present.
trailingSlashCopied when present.

Other keys are ignored.

json
{
  "headers": [
    { "source": "/assets/(.*)", "headers": [{ "key": "cache-control", "value": "public, max-age=31536000, immutable" }] }
  ],
  "rewrites": [{ "source": "/old-blog/:path*", "destination": "/blog/:path*" }]
}

Runtime limits

The server runs on the Edge runtime, not Node.js. Code in your loaders, actions, and API routes must use web-standard APIs. Node-only modules such as fs, child_process, and node:sqlite do not run there. Keep database access and other Node-only work in code that uses a web-compatible client.

The @kiln-js/auth SQLite adapter needs Node, so it cannot run on this target. Use a database adapter that works over HTTP on Vercel.