@vite-deploy/vercel
This adapter allows you to deploy your Vite project to Vercel. Learn how in our Vercel deployment guide.
Vercel is a deployment platform that allows you to host your site by connecting directly to your GitHub repository. This adapter builds your Vite project for deployment through Vercel.
Installation
Section titled “Installation”Starter template
Section titled “Starter template”-
Download a basic template for your favorite host:
Terminal window npx giget@latest gh:web-runes/vite-deploy/examples/vercel-server -
Install dependencies:
Terminal window npm installTerminal window pnpm installTerminal window yarn install -
Start the development server:
Terminal window npm run devTerminal window pnpm devTerminal window yarn dev
Manual install
Section titled “Manual install”-
Add
@vite-deploy/vercelto your project’s dependencies using your preferred package manager:Terminal window npm install @vite-deploy/vercelTerminal window pnpm add @vite-deploy/vercelTerminal window yarn add @vite-deploy/vercel -
Add the plugin to your Vite config file:
vite.config.js import vercel from "@vite-deploy/vercel";import { defineConfig } from "vite";export default defineConfig({plugins: [vercel({output: "server",handlerEntrypoint: "./src/handler.ts",})]}); -
Update your TypeScript config file to include necessary types:
tsconfig.json {"compilerOptions": {"types": ["vite/client","@vite-deploy/vercel/types"]},} -
Create the handler entrypoint:
src/handler.ts import type { ExportedHandler } from "@vite-deploy/vercel";export default {fetch(request) {const url = new URL(request.url);return new Response(`Running ${url.pathname} in ${navigator.userAgent}!`);},} satisfies ExportedHandler; -
Start the development server:
Terminal window npm run devTerminal window pnpm devTerminal window yarn dev
Options
Section titled “Options”The Vercel adapter accepts output related options. It also accepts the following:
handlerEntrypoint
Section titled “handlerEntrypoint”Type: string | URL
Specifies what module should be used. It accepts:
- Paths relative to Vite’s root:
./src/handler.ts. - Absolute paths:
/foo/handler.ts. - Package specifiers:
@my-pkg/handler. - URLs:
new URL("./src/handler.ts", import.meta.url).
import vercel from "@vite-deploy/vercel";import { defineConfig } from "vite";
export default defineConfig({ plugins: [vercel({ // ... handlerEntrypoint: "./src/handler.ts", })]});The module must return a ExportedHandler, which handles requests:
import type { ExportedHandler } from "@vite-deploy/vercel";
export default { fetch(request) { const url = new URL(request.url); return new Response(`Running ${url.pathname} in ${navigator.userAgent}!`); },} satisfies ExportedHandler;requestLoggingLevel
Section titled “requestLoggingLevel”Type: "silent" | "info" | undefined
Default: "info"
Specifies if requests are logged in the terminal. It can be disabled you already handle logging at runtime:
import vercel from "@vite-deploy/vercel";import { defineConfig } from "vite";
export default defineConfig({ plugins: [vercel({ // ... requestLoggingLevel: "silent" })]});