You're reading the 1.x docs. Go to latest

Skip to content

lit-ui-router-ssr / vite / definePrerender

Function: definePrerender() ​

ts
function definePrerender(script): PrerenderEntry;

Defined in: packages/lit-ui-router-ssr/src/vite.ts:131

Turns a callback that returns this package's prerender options into a prerender script's default export. The export spreads the build's values (outDir, base, shellHtml, write) under the options and calls this package's prerender(), so the script never calls it itself.

Without a document hook in the options, each page's body goes into shellHtml, the built index.html, in place of its first <!--app--> marker, so the shell's <head> and client script carry over. A shell with no marker fails the build at the first page written into it; a run that writes none, such as one of redirects only, needs no marker. A document the script returns wins, and can fill any other marker.

Parameters ​

ParameterTypeDescription
scriptPrerenderScriptreturns the prerender options; handed the build's values

Returns ​

PrerenderEntry

the default export for the prerender script, whose result's pages carry their payload report

Throws ​

from the build step, at the first page, when no document is returned and shellHtml has no <!--app--> marker

Example ​

ts
import type { TemplateResult } from 'lit';
import type { UIRouterLit } from 'lit-ui-router';
import type { PrerenderOptions } from 'lit-ui-router-ssr';
import { definePrerender } from 'lit-ui-router-ssr/vite';

declare const mounts: PrerenderOptions['mounts'];
declare const router: UIRouterLit;
declare function page(router: UIRouterLit): TemplateResult;

export default definePrerender(() => ({
  mounts,
  router,
  paths: ['/', '/about'],
  template: page,
}));