From f71e9f84260fe5f88bf3e496ddc4393b1979a5da Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 23 Mar 2024 00:39:01 +0100 Subject: [PATCH] chore: fix SPA and configure it in the example --- .npmrc | 1 + examples/pwa-assets/package.json | 3 +++ examples/pwa-assets/vite.config.ts | 4 ++-- src/config.ts | 11 +++++++---- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.npmrc b/.npmrc index ff0bf76..01aa3e4 100644 --- a/.npmrc +++ b/.npmrc @@ -3,3 +3,4 @@ ignore-workspace-root-check=true shamefully-hoist=true strict-peer-dependencies=false auto-install-peers=true +shell-emulator=true diff --git a/examples/pwa-assets/package.json b/examples/pwa-assets/package.json index 6e5ce76..c0413c7 100644 --- a/examples/pwa-assets/package.json +++ b/examples/pwa-assets/package.json @@ -5,9 +5,12 @@ "type": "module", "scripts": { "build": "remix vite:build", + "build:spa": "SPA=true remix vite:build", "dev": "remix vite:dev", + "dev:spa": "SPA=true remix vite:dev", "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .", "start": "remix-serve ./build/server/index.js", + "start:spa": "npx serve build/client", "typecheck": "tsc" }, "dependencies": { diff --git a/examples/pwa-assets/vite.config.ts b/examples/pwa-assets/vite.config.ts index 6553482..80cc643 100644 --- a/examples/pwa-assets/vite.config.ts +++ b/examples/pwa-assets/vite.config.ts @@ -11,11 +11,11 @@ const { RemixVitePWAPlugin, RemixPWAPreset } = RemixVitePWA() export default defineConfig({ plugins: [ remix({ + ssr: process.env.SPA !== 'true', presets: [RemixPWAPreset()], }), tsconfigPaths(), RemixVitePWAPlugin({ - disable: true, mode: 'development', srcDir: 'app', base: '/', @@ -31,7 +31,7 @@ export default defineConfig({ }, }, workbox: { - globPatterns: ['**/*.{js,css,png,svg,ico}'], + globPatterns: ['**/*.{js,html,css,png,svg,ico}'], }, pwaAssets: { config: true, diff --git a/src/config.ts b/src/config.ts index 5aa4746..dfca8b8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -25,13 +25,16 @@ export function configurePWA( } else { options.workbox = options.workbox ?? {} - if (ssr) { - if (!('navigateFallback' in options.workbox)) + if (!('navigateFallback' in options.workbox)) { + if (ssr) options.workbox.navigateFallback = basename ?? viteOptions.base ?? '/' - if (!('navigateFallbackAllowlist' in options.workbox)) - options.workbox.navigateFallbackAllowlist = [new RegExp(`^${options.workbox.navigateFallback}$`)] + else + options.workbox.navigateFallback = 'index.html' } + if (ssr && !('navigateFallbackAllowlist' in options.workbox)) + options.workbox.navigateFallbackAllowlist = [new RegExp(`^${options.workbox.navigateFallback}$`)] + config = options.workbox }