1

trying to figure out how to host the sveltekit frontend app built with static-adapter.

Here's my svelte config:

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://kit.svelte.dev/docs/integrations#preprocessors
    // for more information about preprocessors
    preprocess: vitePreprocess(),

    kit: {
        // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
        // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
        // See https://kit.svelte.dev/docs/adapters for more information about adapters.
        adapter: adapter({
            // default options are shown
            pages: 'build',
            assets: 'build',
            trailingSlash: 'always',
            fallback: 'index.html',
            precompress: false,
            strict: true
          })
    }
};

export default config;

My root layout.ts:

export const prerender = true;

I then run npm run build and get .sveltekit output directory with the content below find . -maxdepth 3 -ls:

50503435        0 drwxr-xr-x    5 kilinov          staff                 160 28 May 10:53 .
50503483        0 drwxr-xr-x    3 kilinov          staff                  96 28 May 10:53 ./prerendered
50503484        0 drwxr-xr-x    4 kilinov          staff                 128 28 May 10:53 ./prerendered/pages
50503485        8 -rw-r--r--    1 kilinov          staff                1594 28 May 10:53 ./prerendered/pages/index.html
50503486        8 -rw-r--r--    1 kilinov          staff                1525 28 May 10:53 ./prerendered/pages/portal.html
50503436        0 drwxr-xr-x   11 kilinov          staff                 352 28 May 10:53 ./server
50503437        0 drwxr-xr-x    4 kilinov          staff                 128 28 May 10:53 ./server/entries
50503442        0 drwxr-xr-x    4 kilinov          staff                 128 28 May 10:53 ./server/entries/fallbacks
50503443        0 drwxr-xr-x    5 kilinov          staff                 160 28 May 10:53 ./server/entries/pages
50503457        0 drwxr-xr-x    6 kilinov          staff                 192 28 May 10:53 ./server/nodes
50503461        8 -rw-r--r--    1 kilinov          staff                 371 28 May 10:53 ./server/nodes/2.js
50503462        8 -rw-r--r--    1 kilinov          staff                 523 28 May 10:53 ./server/nodes/3.js
50503459        8 -rw-r--r--    1 kilinov          staff                 511 28 May 10:53 ./server/nodes/0.js
50503460        8 -rw-r--r--    1 kilinov          staff                 417 28 May 10:53 ./server/nodes/1.js
50503440        8 -rw-r--r--    1 kilinov          staff                 307 28 May 10:53 ./server/internal.js
50503487        8 -rw-r--r--    1 kilinov          staff                 864 28 May 10:53 ./server/manifest.js
50503438      184 -rw-r--r--    1 kilinov          staff               92547 28 May 10:53 ./server/index.js
50503439        0 drwxr-xr-x    6 kilinov          staff                 192 28 May 10:53 ./server/chunks
50503444       16 -rw-r--r--    1 kilinov          staff                6026 28 May 10:53 ./server/chunks/internal.js
50503449        8 -rw-r--r--    1 kilinov          staff                3347 28 May 10:53 ./server/chunks/ssr.js
50503447       16 -rw-r--r--    1 kilinov          staff                5961 28 May 10:53 ./server/chunks/exports.js
50503445        8 -rw-r--r--    1 kilinov          staff                 825 28 May 10:53 ./server/chunks/index.js
50503456        8 -rw-r--r--    1 kilinov          staff                1220 28 May 10:53 ./server/manifest-full.js
50503441        0 drwxr-xr-x    3 kilinov          staff                  96 28 May 10:53 ./server/.vite
50503446        8 -rw-r--r--    1 kilinov          staff                2387 28 May 10:53 ./server/.vite/manifest.json
50503458        0 drwxr-xr-x    2 kilinov          staff                  64 28 May 10:53 ./server/stylesheets
50503464        0 drwxr-xr-x    5 kilinov          staff                 160 28 May 10:53 ./client
50503465        8 -rw-r--r--    1 kilinov          staff                1571 28 May 10:53 ./client/favicon.png
50503466        0 drwxr-xr-x    4 kilinov          staff                 128 28 May 10:53 ./client/_app
50503469        8 -rw-r--r--    1 kilinov          staff                  27 28 May 10:53 ./client/_app/version.json
50503468        0 drwxr-xr-x    5 kilinov          staff                 160 28 May 10:53 ./client/_app/immutable
50503467        0 drwxr-xr-x    3 kilinov          staff                  96 28 May 10:53 ./client/.vite
50503470        8 -rw-r--r--    1 kilinov          staff                2642 28 May 10:53 ./client/.vite/manifest.json

But I can't see app.html (or any top-level html) anywhere - only in "prerendered" directory. I need to host this app in simple nginx server for now, I'm planning to add some backend calls later when I figure it out.

I was expecting to have a directory that would have index.html plus some JS/css/static stuff and I can then host that app in nginx like so docker run -p 80:80 -v $(pwd):/usr/share/nginx/html nginx

Thank you all in advance!

1 Answer 1

1

You are still using @sveltejs/adapter-auto, which as noted in a generated comment of the config, only supports certain environments. If you want to generate static pages, you have to switch the adapter to @sveltejs/adapter-static.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for this. I've ran npm install for the static adapter, but I may have forgotten to remove old comments from svelte config though. What's the best way to verify that I'm using static adapted?
Ah, I see in the import statement. Will try it out soon, hopefully this is the reason

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.