@wells-nelson/build-tools 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/dist/service-worker.d.ts +11 -3
- package/dist/service-worker.js +7 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,14 +40,19 @@ export default defineConfig(({ mode, command }) => ({
|
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
/// <reference types="@sveltejs/kit" />
|
|
43
|
-
import { version } from '$app/env';
|
|
43
|
+
import { dev, version } from '$app/env';
|
|
44
44
|
import { assets, immutable } from '$app/manifest';
|
|
45
45
|
import { self } from '$app/service-worker';
|
|
46
46
|
import { registerAppShellCache } from '@wells-nelson/build-tools/service-worker';
|
|
47
47
|
|
|
48
|
-
registerAppShellCache({ sw: self, version, files: [...immutable, ...assets], cachePrefix: 'my-app' });
|
|
48
|
+
registerAppShellCache({ sw: self, version, dev, files: [...immutable, ...assets], cachePrefix: 'my-app' });
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
Navigations go to the network first, so starting the app online always loads the latest deploy;
|
|
52
|
+
offline they fall back to the cached shell. A new worker skips waiting and takes over open
|
|
53
|
+
pages. `networkOnly` paths are never cached (default: SvelteKit's `_app/version.json`, so
|
|
54
|
+
`updated` from `$app/state` notices new deploys). `dev` caches nothing.
|
|
55
|
+
|
|
51
56
|
## Templates
|
|
52
57
|
|
|
53
58
|
`templates/deploy-pages.yml` (replace `__REPO__`) and `templates/manifest.webmanifest`.
|
package/dist/service-worker.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Offline-first app shell for a SvelteKit service worker. Everything the app needs is precached
|
|
3
|
-
* on install; navigations
|
|
4
|
-
*
|
|
3
|
+
* on install; navigations go to the network first (so starting the app online always
|
|
4
|
+
* loads the latest deploy) and fall back to the cached shell (the app root) offline. A new
|
|
5
|
+
* deploy's worker installs, skips waiting and takes over open pages straight away. Cross-origin
|
|
6
|
+
* requests (Supabase, Google avatars) are left to the network.
|
|
5
7
|
*
|
|
6
8
|
* ```ts
|
|
7
9
|
* // src/service-worker/index.ts
|
|
@@ -40,8 +42,14 @@ export interface AppShellCacheOptions {
|
|
|
40
42
|
* loads (a cache-first worker would otherwise keep serving stale dev modules).
|
|
41
43
|
*/
|
|
42
44
|
dev?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Paths (relative to the scope) that always go to the network and are never cached. Defaults
|
|
47
|
+
* to SvelteKit's `_app/version.json`, so its update check (`updated` in `$app/state`) sees
|
|
48
|
+
* new deploys instead of the first answer it ever cached.
|
|
49
|
+
*/
|
|
50
|
+
networkOnly?: string[];
|
|
43
51
|
}
|
|
44
|
-
export declare function registerAppShellCache({ sw, version, files, cachePrefix, dev }: AppShellCacheOptions): {
|
|
52
|
+
export declare function registerAppShellCache({ sw, version, files, cachePrefix, dev, networkOnly }: AppShellCacheOptions): {
|
|
45
53
|
cacheName: null;
|
|
46
54
|
precache: never[];
|
|
47
55
|
} | {
|
package/dist/service-worker.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Offline-first app shell for a SvelteKit service worker. Everything the app needs is precached
|
|
3
|
-
* on install; navigations
|
|
4
|
-
*
|
|
3
|
+
* on install; navigations go to the network first (so starting the app online always
|
|
4
|
+
* loads the latest deploy) and fall back to the cached shell (the app root) offline. A new
|
|
5
|
+
* deploy's worker installs, skips waiting and takes over open pages straight away. Cross-origin
|
|
6
|
+
* requests (Supabase, Google avatars) are left to the network.
|
|
5
7
|
*
|
|
6
8
|
* ```ts
|
|
7
9
|
* // src/service-worker/index.ts
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
* registerAppShellCache({ sw: self, version, dev, files: [...immutable, ...assets], cachePrefix: 'my-app' });
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
|
-
export function registerAppShellCache({ sw, version, files, cachePrefix = 'app', dev = false }) {
|
|
19
|
+
export function registerAppShellCache({ sw, version, files, cachePrefix = 'app', dev = false, networkOnly = ['_app/version.json'] }) {
|
|
18
20
|
const CACHE = `${cachePrefix}-cache-${version}`;
|
|
19
21
|
if (dev) {
|
|
20
22
|
sw.addEventListener('install', (event) => event.waitUntil(sw.skipWaiting()));
|
|
@@ -31,6 +33,7 @@ export function registerAppShellCache({ sw, version, files, cachePrefix = 'app',
|
|
|
31
33
|
const scope = new URL(sw.registration.scope);
|
|
32
34
|
// The app root serves the SPA shell (index.html on GitHub Pages, the fallback page elsewhere).
|
|
33
35
|
const SHELL = scope.href;
|
|
36
|
+
const NETWORK_ONLY = new Set(networkOnly.map((p) => new URL(p, scope).pathname));
|
|
34
37
|
const PRECACHE = files.map((f) => new URL(typeof f === 'string' ? f : f.path, scope).href).concat(SHELL);
|
|
35
38
|
sw.addEventListener('install', (event) => {
|
|
36
39
|
event.waitUntil((async () => {
|
|
@@ -52,7 +55,7 @@ export function registerAppShellCache({ sw, version, files, cachePrefix = 'app',
|
|
|
52
55
|
if (request.method !== 'GET')
|
|
53
56
|
return;
|
|
54
57
|
const url = new URL(request.url);
|
|
55
|
-
if (url.origin !== scope.origin)
|
|
58
|
+
if (url.origin !== scope.origin || NETWORK_ONLY.has(url.pathname))
|
|
56
59
|
return;
|
|
57
60
|
if (request.mode === 'navigate') {
|
|
58
61
|
event.respondWith((async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wells-nelson/build-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Build and deployment tooling for Wells Nelson SvelteKit PWAs: postbuild, PWA icon generator, Vite config pieces, service worker, and templates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|