I’m working on a monorepo with the following setup:
index.ts(using the Hono framework withhono/vercel) is compiled usingtsupintodist/functions/index.js- Static assets are built with
Viteintodist/vite/assets
So my build structure ends up like this:
dist/
├── functions/
│ └── index.js ← this is my API handler
└── vite/
└── assets/
My vercel.json looks like this:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"version": 2,
"installCommand": "pnpm install",
"buildCommand": "pnpm turbo run build",
"outputDirectory": "dist",
"rewrites": [
{
"source": "/assets/(.*)",
"destination": "/dist/vite/assets/$1"
},
{
"source": "/(.*)",
"destination": "/dist/functions/index.js"
}
]
}
Even though I set up a rewrite to /functions/index.js, Vercel is treating the file as a static asset instead of a serverless function. The file is publicly available (e.g. site.vercel.app/functions/index.js) but it’s not executed as a function.
I tried changing the tsup output to api/index.js instead (since Vercel treats files inside the /api directory as functions). But that didn’t work, the api/index.js file didn’t show up in the Vercel deployment output. I guess that Vercel doesn’t allow emitting files outside of the declared “outputDirectory” (which is dist), so writing to ../api is being ignored.
Question:
Is there a supported way to include a compiled serverless function in the output directory and still have Vercel treat it as a serverless function?
Or, is there a way to output a file to /api at the root level (outside outputDirectory) so Vercel recognizes it?

