Disable SSR in a SvelteKit project

SSR is great and all, but it can interfere with browser APIs, make porting a project from pure Svelte to SvelteKit somewhat cumbersome, and including some dependencies might be a hassle. Sometimes you might just not need it.

You need to do two things:

  • Install and configure the static adapter
  • Create a hook to disable SSR

To install the static adapter use:

npm i -D @sveltejs/adapter-static

Then go to svelte.config.js and configure it as follows:

Next, create a hooks.js within the src folder with the following content:

And that should be it. Running vite build now should create a build folder, where you will find your static SPA.