Outputs
Vite Deploy allows you to render your Vite project statically (SSG), on-demand (SSR) or both (hybrid).
Below is a recap of requirements for each output:
| Output | Static | Hybrid | Server |
|---|---|---|---|
| Handler entrypoint | Yes | Yes | Yes |
| Prerender entrypoint | Yes | Yes | No |
| Server entrypoint* | No | Yes | Yes |
* Some adapters require an extra server entrypoint for on-demand rendering.
Outputs
Section titled “Outputs”Static (SSG)
Section titled “Static (SSG)”In development, the request handler is used for requests. During the build:
- The prerender entrypoint is called to determine which routes should be rendered statically.
- Requests are sent for each route, handled by the request handler. The result is stored as static HTML.
- The server artifacts are removed, only leaving static assets.
Server (SSR)
Section titled “Server (SSR)”In development, the request handler is used for requests. During the build:
- A standard Vite build takes place
- Some adapters require a different server entrypoint for production.
- No artifacts are removed.
Hybrid
Section titled “Hybrid”In development, the request handler is used for requests. During the build:
- The prerender entrypoint is called to determine which routes should be rendered statically.
- Requests are sent for each route, handled by the request handler. The result is stored as static HTML.
- Some adapters require a different server entrypoint for production.
- No artifacts are removed.
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. Required 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 what module should be used. 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 to use during prerendering:
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: { // ... output: "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 statically replaced which lets you know if the file is running during prerendering or not.
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;