Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building svelte app as a set of static files

I want to use Svelte in my next project, due to its clean syntax and how nice is to work in it. Unfortunately, to deploy the app in my company I can't use node or anything like that on the server. I can only serve the app from nginx as static files.

Is it possible in svelte? I can't find anything that would allow me to do that, all solutions I've tried like @sveltejs/adapter-static didn't seem to generate it correctly to use it in this way. I can't find any guide on how to do that on the web.

like image 272
Djent Avatar asked Dec 17 '25 13:12

Djent


1 Answers

In order to pre-render a SvelteKit 1.0 static site you need to:

  1. Install the static adapter with npm i -D @sveltejs/adapter-static

  2. Put the following in svelte.config.js

/**
 * from https://kit.svelte.dev/docs/adapter-static
 */
import adapter from '@sveltejs/adapter-static';

export default {
    kit: {
        adapter: adapter({
            // default options are shown. On some platforms
            // these options are set automatically — see below
            pages: 'build',
            assets: 'build',
            fallback: null,
            precompress: false,
            strict: true
        })
    }
};
  1. Add to devDependencies in package.json (you can remove the default adapter-auto):
    "@sveltejs/adapter-static": "next",
  1. Add the following line to src/routes/+layout.js - create the file if it does not exist:
    export const prerender = true;
  1. Run npm run build

The static files will be generated in the build directory.

More details at https://kit.svelte.dev/docs/adapter-static and https://github.com/sveltejs/kit/tree/master/packages/adapter-static#sveltejsadapter-static

like image 164
isapir Avatar answered Dec 19 '25 07:12

isapir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!