Skip to main content
The @sveltejs/adapter-static adapter prerenders your entire site as a collection of static files.

Installation

Usage

1

Install the adapter

Add it to your svelte.config.js:
2

Make all routes prerenderable

Add export const prerender = true to your root layout:

Configuration options

From the adapter type definitions:

pages

The directory to write prerendered pages to. Defaults to 'build'.

assets

The directory to write static assets to. Defaults to the same directory as pages.

fallback

Specify a fallback page for single-page app (SPA) mode. This is useful if you have dynamic routes that can’t be prerendered.
The fallback page will be generated and used for any route that doesn’t match a prerendered page:
When using a fallback page, you should configure your deployment platform to serve it for 404s. Otherwise, your app won’t work for client-side navigation.

precompress

Enables precompression of static files using gzip and brotli.
From the implementation:

strict

By default, adapter-static checks that all routes are prerenderable. Set to false to disable this check.
If strict is false, any non-prerendered routes will be unavailable in the final build.

Prerendering all routes

You have several options to make all routes prerenderable:

Error handling

The adapter will fail the build if it encounters dynamic routes that cannot be prerendered:
If you have routes with parameters like /blog/[slug], you must either:
  • Add them to prerender.entries in your config
  • Add export const prerender = true and a load function that returns all possible parameter values
  • Set strict: false (not recommended)

Platform-specific zero-config mode

Some platforms are automatically detected, and the adapter will use optimized defaults:

Single-page apps (SPAs)

To create a SPA where all routes are handled client-side:
For SPAs, configure your web server to serve index.html for all routes. Most static hosts have this built in.

Deployment

After building, the output directory contains only static files:
You can deploy this directory to any static hosting service: