Warning
🚧 Work In Progress
You are on the Vite Environment API development branch. Check out v9 branch current stable version.
Vercel adapter for Vite 6.
Bundle your Vite application as supported by Vercel Output API (v3).
npm i -D vite-plugin-vercel
yarn add -D vite-plugin-vercel
pnpm add -D vite-plugin-vercel
bun add -D vite-plugin-vercel
- SSG/Static files
- see
prerender
config
- see
- SSR/Serverless functions
.[jt]s
files under the<root>/api
folder of your project are automatically bundled as Serverless functions under.vercel/output/functions/api/*.func
- see
additionalEndpoints
config
- ISR/Prerender functions
- see
isr
config. Also see implementation of vike for example
- see
- Edge functions
- Edge middleware
- Images optimization
- Preview mode
- Advanced config
Install this package as a dev dependency and add it to your Vite config:
// vite.config.ts
import { defineConfig } from 'vite';
import vercel from 'vite-plugin-vercel';
import { getEntriesFromFs } from "vite-plugin-vercel/utils";
export default defineConfig({
plugins: [vercel({
entries: [
...(await getEntriesFromFs("_api", {
// Auto mapping examples:
// _api/page.ts -> /api/page
// _api/post.ts -> /api/post
// _api/name/[name].ts -> /api/name/*
destination: "api",
}))
]
})],
});
Note
Prefer using /_api
directory, as @vercel/build
is currently force building /api
files,
with no way to disable it, thus avoiding double compilation and unexpected behaviour.
Endpoints under /api
, /_api
or added through additionalEndpoints
can be configured
by exporting values from the endpoint file:
// file: _api/endpoint.ts
// Should run on edge runtime
export const edge = true;
// Always add those header to this endpoint
export const headers = {
'Some-Header': 'some value',
};
// Stream the response
export const streaming = true;
// Enable Incremental Static Regeneration for this endpoint
export const isr = {
expiration: 30,
};
export default async function handler() {
return new Response('Edge Function: OK', {
status: 200,
});
}
You can use Edge middleware as describe in the official documentation (i.e. with a middleware.ts
file at the root of your project).
Nothing. It's a production-only feature
Nothing (yet?). If you have a use-case where an actual Edge runtime would be necessary in dev, please open a discussion
This is not yet supported. Please open an issue if you need this (PR welcome).
Related documentation: https://vercel.com/docs/edge-network/headers/request-headers
TODO