Prerendering

Routes marked with prerender are rendered to static HTML files at build time, and any static file host can then serve dist/client directly — with no server required:

// routes/about/+page.ts
import component from "@/views/About.torp";
import { type PageEndPoint } from "@torpor/build";

export default {
	component,
	prerender: true,
} satisfies PageEndPoint;

Layouts inherit the flag to every route below them, so a whole section (or the whole site, via a top-level _layout.ts) can be prerendered, and a single route can opt back out by setting prerender: false. Interactivity is unaffected: the client entry still hydrates each prerendered page. Take care, though: server hooks and load functions run at build time with a synthetic request — there are no cookies — so a hook that reads the session would bake one user's data into the page for everyone. Keep personalization on dynamic routes, or fetch it client-side.

Dynamic routes

A dynamic route needs params to build with. Declare them with params entries — one entry per page to render — typed by the route's annotation:

// routes/posts/[id]/+page.server.ts
import { type PageServerEndPoint } from "@torpor/build";

export default {
	prerender: {
		params: [{ id: "1" }, { id: "2" }, { id: "3" }],
	},
	load: async ({ params }) => ok(await getPost(params.id)),
} satisfies PageServerEndPoint<"/posts/[id]">;

Rest segments spread too: { path: "a/b" } under /docs/[...path] renders /docs/a/b.

A site-level default

Set site.prerender in your config file to flag lots of routes at once — a boolean, or a map of paths (exact, or /** for a path and everything below it) with the most specific match winning. Route and layout flags always take precedence:

// site.config.ts
import { Site } from "@torpor/build";

const site = new Site();
site.prerender = {
	"/blog/**": true, // including /blog/...
	"/account": false, // stays dynamic
};

export default site;

Any page route without its own flag and without a layout flag uses it.

Notes

  • The _error page, if the site has one, is rendered to 404.html for static hosts to use
  • Navigation between a prerendered page and a dynamic one works normally; if a page's data can't be loaded on the client (e.g. a prerendered site with no server), the browser does a full page load instead
  • For a static host like GitHub Pages, serve dist/client directly, adding a .nojekyll file