@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.
bun add -d @kiln-js/adapter-vercelWhat it produces#
Running the adapter writes .vercel/output inside the project root:
.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:
vercel deploy --prebuiltadaptVercel(options)#
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#
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:
- Deletes any previous
.vercel/output. - Copies the client build into
static/. - Reads the manifest and builds the list of stylesheet links and the entry script URL.
- Writes a small Edge entry file to
.kiln/vercel-entry.ts. It imports the server bundle and callscreateHandlerwith the asset list. - Bundles that entry into
functions/index.func/index.js. The bundle targets the browser platform with ES2022, minified, andprocess.env.NODE_ENVset toproduction. - Writes
config.json, which describes routing.
Bundlers#
"bun"usesBun.buildwhen 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:
handle: "filesystem": serve a static file when one exists at the path.- Any
rewritesfromvercel.json. /(.*)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:
| Key | Effect |
|---|---|
headers | Copied to config.json. |
redirects | Copied to config.json. |
rewrites | Converted to Vercel routes, placed before the Kiln catch-all. Each rewrite is { source, destination }. |
cleanUrls | Copied when present. |
trailingSlash | Copied when present. |
Other keys are ignored.
{
"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.

