Skip to content

Commit

Permalink
chore: fix SPA and configure it in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Mar 22, 2024
1 parent e838ad1 commit f71e9f8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ignore-workspace-root-check=true
shamefully-hoist=true
strict-peer-dependencies=false
auto-install-peers=true
shell-emulator=true
3 changes: 3 additions & 0 deletions examples/pwa-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions examples/pwa-assets/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
Expand All @@ -31,7 +31,7 @@ export default defineConfig({
},
},
workbox: {
globPatterns: ['**/*.{js,css,png,svg,ico}'],
globPatterns: ['**/*.{js,html,css,png,svg,ico}'],
},
pwaAssets: {
config: true,
Expand Down
11 changes: 7 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit f71e9f8

Please sign in to comment.