Outputs
Vite Deploy allows you to render your Vite project statically (SSG), on-demand (SSR) or both (hybrid).
Entrypoints
Section titled “Entrypoints”A Vite Deploy project is wired together through up to three entrypoints. Each one is a regular module that Vite builds: you can write it yourself, import it from a package, or have a framework provide it.
- Handler entrypoint: answers HTTP requests. This is your application: a
fetchhandler (or, for the Node adapter, optionally a Node style handler). It runs in dev, during prerendering, and at runtime in production. - Prerender entrypoint: lists which routes to render to static HTML at build time. Required only when prerendering is involved.
- Server entrypoint: boots the production server (e.g.
http.createServer,Deno.serve,Bun.serve). Only some adapters need one, most platforms (Cloudflare, Netlify, Vercel) provide their own runtime so you don’t write a server entrypoint there.
Below is a recap of which entrypoints each output requires:
| Output | Static | Server | Hybrid | | -------------------- | ------ | ------ | ------ | | Handler entrypoint | Yes | Yes | Yes | | Prerender entrypoint | Yes | No | Yes | | Server entrypoint* | No | Yes | Yes |
* Only required by adapters that produce a standalone server (currently the Node adapter).
How each output works
Section titled “How each output works”In development, every output uses the request handler to answer requests. They differ only in what the build produces.
Static (SSG)
Section titled “Static (SSG)”- The prerender entrypoint is called to determine which routes should be rendered statically.
- A request is sent for each route, handled by the request handler, and the result is stored as static HTML.
- The server bundle is discarded — only static files remain.
Server (SSR)
Section titled “Server (SSR)”- Some adapters require a separate server entrypoint for production; if so, it’s bundled.
- The build keeps both client and server bundles. Nothing is prerendered.
Hybrid
Section titled “Hybrid”- The prerender entrypoint is called to determine which routes should be rendered statically.
- A request is sent for each route, handled by the request handler, and the result is stored as static HTML.
- Some adapters require a separate server entrypoint for production; if so, it’s bundled.
- The server bundle is kept so on-demand routes still work at runtime.
Configuration reference
Section titled “Configuration reference”output
Section titled “output”Type: "static" | "server" | "hybrid"
Specifies the output target for builds:
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... output: "hybrid" })]});prerender
Section titled “prerender”Type: PrerenderOptions | undefined
Default: undefined
Specifies options related to prerendering. Can only be specified if output is set to "static" or "hybrid":
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... output: "static", prerender: { /* ... */ } })]});prerender.entrypoint
Section titled “prerender.entrypoint”Type: string | URL
Specifies the module that lists the routes to prerender. It accepts:
- Paths relative to Vite’s root:
./src/prerender.ts. - Absolute paths:
/foo/prerender.ts. - Package specifiers:
@my-pkg/prerender. - URLs:
new URL("./src/prerender.ts", import.meta.url).
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... output: "static", prerender: { entrypoint: "./src/prerender.ts" } })]});The module must return a PrerenderEntrypoint, which lists URLs to prerender. It is processed by Vite:
import type { PrerenderEntrypoint } from "@vite-deploy/netlify";
export default { getStaticPaths() { return ["/"]; },} satisfies PrerenderEntrypoint;getStaticPaths() can also be asynchronous.
prerender.headers
Section titled “prerender.headers”Type: Headers | undefined
Default: undefined
Specifies headers attached to each request the build sends to your handler during prerendering. Useful for flagging prerender requests so the handler can branch on them, or for supplying credentials your handler expects:
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... output: "static", prerender: { // ... headers: new Headers([["x-foo", "bar"]]) } })]});These headers can then be retrieved during the request:
import type { ExportedHandler } from "@vite-deploy/netlify";
export default { fetch(request) { if (request.headers.has("x-foo")) { // ... } // ... },} satisfies ExportedHandler;prerender.format
Section titled “prerender.format”Type: "directory" | "file"
Default: "file"
Specifies the output file format of each page:
"file": Vite Deploy will generate an HTML file named for each page route. (e.g./fooand/foo.htmlboth build the file/foo.html)."directory": Vite Deploy will generate a directory with a nestedindex.htmlfile for each page. (e.g./fooand/foo.htmlboth build the file/foo/index.html).
import netlify from "@vite-deploy/netlify";import { defineConfig } from "vite";
export default defineConfig({ plugins: [netlify({ // ... output: "static", prerender: { // ... format: "directory" } })]});import.meta.env.PRERENDER
Section titled “import.meta.env.PRERENDER”In addition to built-in Vite environment variables, Vite Deploy exposes import.meta.env.PRERENDER.
It’s a boolean indicating whether the file is running during prerendering. Vite replaces it with true or false at build time, so the unused branch is dead-code-eliminated and never ships.
This is useful, for example, to expose some routes for prerendering only in hybrid builds:
import type { ExportedHandler } from "@vite-deploy/netlify";import { Hono } from "hono";
const app = new Hono();
if (import.meta.env.DEV || import.meta.env.PRERENDER) { app.get("/", (c) => c.html("<div>foo</div>"));}
app.get( "*", (c) => new Response( `Running ${new URL(c.req.url).pathname} in ${navigator.userAgent}!`, ),);
export default app satisfies ExportedHandler;