Sierra guide / Building
Prerendering
Under target: 'static' a route is rendered to its own index.html at build time, so a visitor and a crawler get the page before any script runs. Declaring render: static makes that a promise, and the build fails if the page cannot be made.
---
render: static
---
<script>
export let data = null
</script>
<h1>{data.name}</h1>
// src/routes/products/[slug].meta.js
export async function load({ params }) {
return { name: `Product ${params.slug}` }
}
export async function getStaticPaths() {
return [{ slug: 'tee' }, { slug: 'mug' }]
}
What else it can do
render: spaopts one route out, and the browser renders it- A dynamic route needs a
getStaticPaths()companion to say which paths exist - The build checks what each
load()read against the schema's@@gateand refuses to publish a page that would expose gated data dbin the config names the Litestone client that check reads throughstatus: draftandredirect:routes are not prerendered, and a redirect lands in_redirectshead()in the companion answers{ title, description, meta, links, jsonLd }for each pagedocument: { bodyClass, lang, head, bodyEnd, meta, links, jsonLd }wraps every page, and the build's own stylesheets are linked for you- A layout reads
pagewhile it prerenders as it does in the browser
In depth: README § Build targets, § The document around a prerendered page