From 5a23c56ed72be19af01ba9f22a9c8b9731c804d0 Mon Sep 17 00:00:00 2001 From: Vojtech Simetka Date: Fri, 27 Oct 2023 11:29:30 +0200 Subject: [PATCH] build: add mechanism to build SPA version of the app --- README.md | 8 ++++++++ package.json | 1 + pnpm-lock.yaml | 11 +++++++++++ svelte.config.js | 10 +++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae7684cb..5468adc0 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ pnpm build You can preview the production build with `pnpm preview`. +If you want to create a build that can be statically served, you need to set env `STATIC=TRUE`. + +```bash +STATIC=TRUE pnpm build +``` + +The outcome is in `build` folder. + ## Config Use env variables to specify: diff --git a/package.json b/package.json index b157f45a..47f2ded4 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@fontsource/source-sans-pro": "^5.0.4", "@multiformats/multiaddr": "^12.1.3", "@sveltejs/adapter-auto": "^2.1.0", + "@sveltejs/adapter-static": "^2.0.3", "@sveltejs/kit": "^1.21.0", "@total-typescript/ts-reset": "^0.4.2", "@typechain/ethers-v6": "^0.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fe5dd1d1..721d5cc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ devDependencies: '@sveltejs/adapter-auto': specifier: ^2.1.0 version: 2.1.0(@sveltejs/kit@1.21.0) + '@sveltejs/adapter-static': + specifier: ^2.0.3 + version: 2.0.3(@sveltejs/kit@1.21.0) '@sveltejs/kit': specifier: ^1.21.0 version: 1.21.0(svelte@4.0.3)(vite@4.3.9) @@ -2100,6 +2103,14 @@ packages: import-meta-resolve: 3.0.0 dev: true + /@sveltejs/adapter-static@2.0.3(@sveltejs/kit@1.21.0): + resolution: {integrity: sha512-VUqTfXsxYGugCpMqQv1U0LIdbR3S5nBkMMDmpjGVJyM6Q2jHVMFtdWJCkeHMySc6mZxJ+0eZK3T7IgmUCDrcUQ==} + peerDependencies: + '@sveltejs/kit': ^1.5.0 + dependencies: + '@sveltejs/kit': 1.21.0(svelte@4.0.3)(vite@4.3.9) + dev: true + /@sveltejs/kit@1.21.0(svelte@4.0.3)(vite@4.3.9): resolution: {integrity: sha512-CBsYoI34SjtOQp0eG85dmVnvTR3Pjs8VgAQhO0CgQja9BIorKl808F1X8EunPhCcyek5r5lKQE1Mmbi0RuzHqA==} engines: {node: ^16.14 || >=18} diff --git a/svelte.config.js b/svelte.config.js index 49389fd6..613c6f12 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,4 +1,5 @@ import adapter from '@sveltejs/adapter-auto' +import adapterStatic from '@sveltejs/adapter-static' import preprocessor from 'svelte-preprocess' /** @type {import('@sveltejs/kit').Config} */ @@ -11,7 +12,14 @@ const config = { // 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(), + adapter: process.env.STATIC + ? adapterStatic({ + // default options are shown + pages: 'build', + assets: 'build', + fallback: 'index.html', + }) + : adapter(), }, }