@vite-deploy/netlify
This adapter allows you to deploy your Vite project to Netlfy. Learn how in our Netlify deployment guide.
Netlify 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 Netlify.
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/netlify-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/netlifyto your project’s dependencies using your preferred package manager:Terminal window npm install @vite-deploy/netlifyTerminal window pnpm add @vite-deploy/netlifyTerminal window yarn add @vite-deploy/netlify -
Add the plugin to your Vite config file:
vite.config.js import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";export default defineConfig({plugins: [netlify({output: "server",handlerEntrypoint: "./src/handler.ts",})]}); -
Update your TypeScript config file to include necessary types:
tsconfig.json {"compilerOptions": {"types": ["vite/client","@vite-deploy/netlify/types"]},} -
Create the handler entrypoint:
src/handler.ts import type { ExportedHandler } from "@vite-deploy/netlify";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 Netlify 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 netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... handlerEntrypoint: "./src/handler.ts", })]});The module must return a ExportedHandler, which handles requests:
import type { ExportedHandler } from "@vite-deploy/netlify";
export default { fetch(request, context) { const url = new URL(request.url); return new Response(`Running ${url.pathname} in ${navigator.userAgent}!`); },} satisfies ExportedHandler;config
Section titled “config”Type: NetlifyPluginOptions | undefined
Default: undefined
Options forwarded to @netlify/vite-plugin, except middleware and build:
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... config: { blobs: { enabled: true }, } })]});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 netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... requestLoggingLevel: "silent" })]});