nginx-docker-static-svelte Svelte Themes

Nginx Docker Static Svelte

Docker image with basic Nginx server for Svelte static adapter.

nginx-docker-static-svelte

Docker image with basic Nginx server for Svelte static adapter.

Code updates

Update your svelte.config.js e.g. following way:

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

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter({
            // default options are shown. On some platforms
            // these options are set automatically — see below
            pages: 'build',
            assets: 'build',
            fallback: undefined,
            precompress: false,
            strict: true
        })
    },
    preprocess: vitePreprocess()
};

export default config;

Then make sure that in src/routes/+layout.js you have the following code:

export const prerender = true;
export const trailingSlash = 'always';

Usage (docker compose example)

You can serve your static build e.g. using docker-compose like this:

version: '3'

services:
  foo:
    container_name: foo
    image: zanne/nginx-docker-static-svelte:latest
    restart: unless-stopped
    ports:
      - 80:80
    volumes:
      - /dir/with/contents:/usr/share/nginx/html

Top categories

Loading Svelte Themes