OxyPages

How To Build A SvelteKit Static Site With Adapter-Static

How To Build A SvelteKit Static Site With adapter-static

Build a SvelteKit static site with adapter-static: the SvelteKit 3 config, the prerender line, what lands in build/, which routes need a server, and SPA mode.

The OxyPages Team · · 7 min read

You've built something in SvelteKit, and you want it on a plain static host instead of a platform that runs a server for you. You swap in adapter-static, run the build, and get a wall of text saying your routes "must be fully prerenderable".

That error is SvelteKit doing you a favour. It's telling you, before anything ships, which parts of your app still expect a server. Fix those, and you get a SvelteKit static site: a build folder of real HTML pages that any host can serve.

I set one up on 8 November 2026 with a fresh project from npx sv create, which now scaffolds SvelteKit 3. Two things have changed since most tutorials were written. The config moved out of svelte.config.js into vite.config.js, and the error messages are clearer than they used to be. Both show up below.

Here's the whole path: installing the adapter, the one line that makes everything prerender, what the build writes, which routes can't be static, and when SPA mode is the right call instead. If you've put a Vite app online before, deploying a Vite app from its dist folder is the same idea with a different folder name.

TL;DR: Install @sveltejs/adapter-static, swap it in for adapter-auto in your config (vite.config.js on SvelteKit 3, svelte.config.js on SvelteKit 2), and add export const prerender = true; to src/routes/+layout.js. npm run build then writes every page to build/ as HTML. Pages with form actions, request-time endpoints or per-visitor content can't be prerendered, and the build tells you which ones. SPA mode with a fallback page exists, but the SvelteKit docs warn about its performance and SEO costs, so prerender first.

What Is adapter-static In SvelteKit?

adapter-static is the SvelteKit adapter that turns your whole app into static files. The SvelteKit docs for adapter-static describe it as the way to use SvelteKit "as a static site generator", prerendering your entire site "as a collection of static files."

Every SvelteKit project has an adapter. A new one starts with adapter-auto, which detects the platform you deploy to and picks a server adapter for it. That's ideal for Vercel, Netlify or Cloudflare, and no help at all for a host that only serves files. So the first step is to replace it.

How To Set Up A SvelteKit Static Site

Three changes, and the build does the rest.

1. Install The Adapter

npm i -D @sveltejs/adapter-static

Or let the Svelte CLI do the install and the config edit together: npx sv add sveltekit-adapter="adapter:static". My test pulled in @sveltejs/adapter-static 4.0.1.

2. Swap It Into Your Config

On SvelteKit 3, the config lives in vite.config.js, passed to the sveltekit() plugin. The SvelteKit 3 migration guide says svelte.config.js "is no longer supported":

import adapter from '@sveltejs/adapter-static';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    sveltekit({
      adapter: adapter({
        pages: 'build',
        assets: 'build',
        fallback: undefined,
        precompress: false,
        strict: true
      })
    })
  ]
});

Those are the defaults, so adapter() with no options does the same thing. On SvelteKit 2, the same adapter(...) call goes under kit.adapter in svelte.config.js.

3. Turn On Prerendering

Create src/routes/+layout.js with one line:

export const prerender = true;

Because it's the root layout, every page inherits it. Without it, my build stopped with:

@sveltejs/adapter-static: all routes must be fully prerenderable,
but found the following routes that are dynamic:
  - src/routes/

The message goes on to list the fixes, which is a nice change. Add the line, run npm run build, and look for Wrote site to "build" at the end.

What Does The build Folder Contain?

The build folder holds one HTML file per page, the app's JavaScript and CSS under _app/immutable, and anything from your static folder. My test app had a home page and an about page, and the whole folder came to 136 KB:

build/
  index.html
  about.html
  robots.txt
  _app/version.json
  _app/immutable/...   (hashed JS and CSS)

Notice about.html, not about/index.html. SvelteKit's trailingSlash option defaults to 'never', so /about is written as a file. Most static hosts serve about.html when someone asks for /about, but not all do. The adapter docs say that if yours doesn't, set export const trailingSlash = 'always'; in the root layout to get about/index.html instead.

Each page is fully rendered HTML, then SvelteKit hydrates it in the browser and takes over navigation. So you get readable pages for search engines and link previews, and app-like navigation for visitors. Refreshing a deep link works without any fallback, because the file is there. That's the practical difference between a prerendered site and what a static website is in general: same files, plus a client-side app layered on top.

Which Routes Can't Be Static?

Which Routes Can't Be Static? - OxyPages

A route can't be prerendered if it needs a live server to answer. The SvelteKit docs boil it down to one rule: "for a page to be prerenderable, any two users hitting it directly must get the same content from the server."

These are the cases that break it:

  • Form actions. I added a contact page with a default action in +page.server.js, and the build failed with "Cannot prerender pages with actions". A server must handle the POST.
  • Reading url.searchParams during prerendering. The docs say it's forbidden at build time. Read query strings in the browser instead, for example in onMount.
  • Per-visitor content. Anything that depends on cookies, sessions or who's signed in. Prerendered HTML is the same for everyone.
  • Endpoints that read the request. A +server.js that handles POST, or reads headers, needs a server. One that returns the same JSON every time can prerender into a file.
  • Dynamic routes nobody links to. SvelteKit finds pages by crawling links from your other pages. A /blog/[slug] page with no link pointing at it won't be built. Export an entries function that returns every slug, and it will be.

Notice what isn't on the list. Loading data from a CMS or an API in a load function is fine, because it runs once at build time. Pages with [parameters] are fine too, as long as SvelteKit can find them.

If you need any of the first four, adapter-static is the wrong adapter. Use adapter-node on a server, or the Vercel, Netlify or Cloudflare adapters, which all run SvelteKit's server features. OxyPages is in the same boat as every static host: it serves the build folder and runs no server code, so form actions need one of those platforms.

Should You Use SPA Mode Instead?

Should You Use SPA Mode Instead? - OxyPages

Usually not. SPA mode means setting a fallback page so the app renders entirely in the browser, and the SvelteKit docs say it has "large negative performance and SEO impacts". They recommend it only in narrow cases, such as wrapping the site in a mobile app.

If you do need it, for an app that's all behind a sign-in screen for example, it's two settings: ssr = false in the root layout, and a fallback name in the adapter options. The docs suggest 200.html and say to avoid index.html where possible, because it can clash with a prerendered home page.

The catch is that each host needs to be told to serve that fallback:

HostFallback to useHow the host finds it
Netlify200.htmlAdd /* /200.html 200 to a _redirects file in static
Surge200.htmlServed automatically for unmatched paths
GitHub Pages404.htmlGitHub serves it for any missing path, with a 404 status
Apache200.htmlA rewrite rule in static/.htaccess, shown in the SvelteKit docs
A host with a fixed index.html fallbackindex.htmlOnly if no page is prerendered as the home page

The general version of this problem, for every framework, is covered in how to fix a 404 on refresh.

My recommendation: prerender every page you can, even inside an otherwise client-heavy app. The docs say the same, and it's the difference between a site that loads with content and one that loads a blank page first.

Walkthrough: From adapter-auto To A Live Static Site

Here's the full sequence on a fresh project:

  1. Run npx sv create my-site, pick the minimal template, and let it install.
  2. Run npm i -D @sveltejs/adapter-static.
  3. In vite.config.js, change the import from @sveltejs/adapter-auto to @sveltejs/adapter-static.
  4. Create src/routes/+layout.js containing export const prerender = true;.
  5. Run npm run build. Fix anything the error output lists, then build again.
  6. Run npm run preview and click every page. Then refresh on each one.
  7. Upload the contents of build to your host, or connect the repository and set the output folder to build. The upload steps are the same as for any Vite build, with build in place of dist.

For a GitHub Pages project site, also set paths.base to your repository name and add an empty .nojekyll file to static, both from the adapter docs.

What To Do Next

Swap the adapter, add the prerender line, and run the build. The error output is your to-do list: each route it names either gets fixed, gets an entries function, or tells you this app needs a server after all.

If the build finishes cleanly, put your SvelteKit build online with OxyPages by uploading the build folder or connecting the repository.

FAQ

Do I Need adapter-static For A SvelteKit Static Site?

Yes. The default adapter-auto targets platforms that run a server. adapter-static is the one that writes your prerendered pages to a folder any static host can serve, and it checks that nothing was left needing a server.

Where Is svelte.config.js In SvelteKit 3?

It's gone. SvelteKit 3 reads project config from the sveltekit() plugin in vite.config.js, and options that used to sit under kit are now top-level plugin options. Running npx sv migrate sveltekit-3 can move most of them for you.

Why Does adapter-static Say My Routes Are Dynamic?

Because nothing told SvelteKit to prerender them. Add export const prerender = true; to src/routes/+layout.js. If the error then names a specific route, that route uses something that needs a server, like a form action, and has to change or move to a server adapter.

Can A SvelteKit Static Site Still Fetch Data?

Yes, in two ways. A load function runs at build time and bakes the data into the HTML, which suits content from a CMS. Code in the browser, like an onMount call to a public API, runs on every visit and suits data that changes often.

Try It Now

Still Here? Drop It In.

The whole pitch fits in one sentence: your HTML, on a link, in seconds.

Drag and drop your HTML files, a folder, a ZIP, your app's build folder, a PDF, an image or an MP3

or ·

No account needed. Your unclaimed website stays live for 30 minutes on a free subdomain. Claim it to your account to keep it permanently.

  • No Account Needed
  • Free SSL
  • 30-Minute Unclaimed Link, Claim To Keep It