mirror of
https://github.com/tiennm99/nntv.git
synced 2026-10-20 00:15:37 +00:00
feat(pwa): precache the app shell so the game plays offline
There was no service worker, so a cold load with the network off failed at the HTTP layer before any of this dependency-free code could run. scope and start_url are relative because the site is served from a Pages subpath, not a domain root. Icons are kept to files the precache glob does not already sweep up: listing one twice under two revisions makes Workbox reject its install handler, and the worker then activates with an empty cache, which looks identical to success until the network is pulled. Verified by serving the build from a /nntv/ subpath, killing the server, and reloading: renders and starts a run with zero network requests.
This commit is contained in:
1 parent
2c8b0dc89b
commit
3000146886
3 files changed
+3206
-19
No files matched your search
@@ -17,6 +17,7 @@
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||
"vite": "^6.4.3",
|
||||
"vite-plugin-pwa": "^1.3.0",
|
||||
"vitest": "^4.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
Generated
+3162
-18
File diff suppressed because it is too large.
Load diff
+43
-1
@@ -1,8 +1,50 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [svelte()],
|
||||
plugins: [
|
||||
svelte(),
|
||||
// Precaches the built app shell + assets so a second visit works with
|
||||
// the network off. `start_url`/`scope` are relative — this app is served
|
||||
// from a GitHub Pages subpath (/nntv/), not a domain root, and an
|
||||
// absolute '/' here would silently break that deployment.
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
includeAssets: ['favicon.png'],
|
||||
manifest: {
|
||||
name: 'Night Ninja: Twilight Voyage',
|
||||
short_name: 'Night Ninja',
|
||||
description: 'Turn-based stealth puzzle game: guide a ninja rabbit past vegetable guards to rescue the carrot princess.',
|
||||
start_url: './',
|
||||
scope: './',
|
||||
display: 'fullscreen',
|
||||
background_color: '#0a0a1a',
|
||||
theme_color: '#0a0a1a',
|
||||
// Every icon listed here is also precached, with a content hash.
|
||||
// Anything already swept up by `globPatterns` below would then be
|
||||
// listed twice under two different revisions, and Workbox rejects
|
||||
// a precache list with conflicting entries — the install handler
|
||||
// throws, the worker activates with an EMPTY cache, and offline
|
||||
// silently does nothing. Keep icons to files globPatterns misses.
|
||||
icons: [
|
||||
{ src: 'favicon.png', sizes: '32x32', type: 'image/png' },
|
||||
// 192 and 512 are the sizes an install prompt actually requires;
|
||||
// without both, browsers silently decline to offer installation.
|
||||
{ src: 'icon-192.png', sizes: '192x192', type: 'image/png', purpose: 'any' },
|
||||
{ src: 'icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' },
|
||||
{ src: 'icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
|
||||
],
|
||||
},
|
||||
workbox: {
|
||||
// Default globPatterns only match js/css/html; this app's weight
|
||||
// is media, so precache the art and audio too. webp carries the
|
||||
// key art — omitting it would leave those images network-only and
|
||||
// break the offline requirement for the menu and ending screens.
|
||||
globPatterns: ['**/*.{js,css,html,png,webp,mp3,ico,webmanifest}'],
|
||||
},
|
||||
}),
|
||||
],
|
||||
// Relative asset paths — makes the built index.html work when opened
|
||||
// directly (file://) or served from any subpath, not just the server root.
|
||||
base: './',
|
||||
|
||||
Reference in new issue
Block a user