diff --git a/astro.config.mjs b/astro.config.mjs index f897e80..2a3bad7 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,6 +1,5 @@ import { defineConfig } from 'astro/config'; import serviceWorker from '@ayco/astro-sw'; - import sitemap from "@astrojs/sitemap"; // https://astro.build/config @@ -9,11 +8,14 @@ export default defineConfig({ integrations: [ sitemap(), serviceWorker({ - path: './src/sw.js', + path: './src/sw.ts', assetCachePrefix: 'ayco-personal-site', excludeRoutes: [ '/threads' - ] + ], + esbuild: { + minify: true + } }) ] }); diff --git a/package.json b/package.json index d74523b..4d4c01a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@astro-reactive/form": "^0.10.0", "@astro-reactive/validator": "^0.5.0", "@astrojs/sitemap": "^3.1.6", - "@ayco/astro-sw": "^0.7.8", + "@ayco/astro-sw": "^0.7.9", "astro": "^4.14.2", "astro-github-stats": "^0.7.0", "astro-iconify": "^1.2.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 252852f..a2f95ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,8 +18,8 @@ importers: specifier: ^3.1.6 version: 3.1.6 '@ayco/astro-sw': - specifier: ^0.7.8 - version: 0.7.8 + specifier: ^0.7.9 + version: 0.7.9 astro: specifier: ^4.14.2 version: 4.14.2(@types/node@22.4.0)(rollup@4.20.0)(typescript@5.5.4) @@ -75,8 +75,8 @@ packages: resolution: {integrity: sha512-/ca/+D8MIKEC8/A9cSaPUqQNZm+Es/ZinRv0ZAzvu2ios7POQSsVD+VOj7/hypWNsNM3T7RpfgNq7H2TU1KEHA==} engines: {node: ^18.17.1 || ^20.3.0 || >=21.0.0} - '@ayco/astro-sw@0.7.8': - resolution: {integrity: sha512-NA3m2YXNReZQla3tv98rJ89HfftmEC+4dsX/bG+NIIlFVcnGTxvwPdhTZ3vD5K/NqVyo7wr4n132k4dCtKUWvw==} + '@ayco/astro-sw@0.7.9': + resolution: {integrity: sha512-hVdRdZz+IJvmg/qpWHX52dK0Pnp8ErsMy1lYcs7g3rueLDS+r5JdFwdfs3GgU5DyDBfBg/VJZ7dWETYS+sUrYw==} engines: {node: '>=18.0.0'} '@babel/code-frame@7.24.7': @@ -2270,7 +2270,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@ayco/astro-sw@0.7.8': + '@ayco/astro-sw@0.7.9': dependencies: esbuild: 0.23.1 pathe: 1.1.2 diff --git a/src/sw.js b/src/sw.ts similarity index 94% rename from src/sw.js rename to src/sw.ts index f873a6e..909eb8f 100644 --- a/src/sw.js +++ b/src/sw.ts @@ -5,13 +5,13 @@ */ const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}` -const addResourcesToCache = async (resources) => { +const addResourcesToCache = async (resources: string[]) => { const cache = await caches.open(cacheName); console.log('[personal-sw]: adding resources to cache...', resources) await cache.addAll(new Set([...resources])); }; -const putInCache = async (request, response) => { +const putInCache = async (request: Request, response: Response) => { const cache = await caches.open(cacheName); console.log('[personal-sw]: adding one response to cache...', request.url) // if exists, replace @@ -25,7 +25,7 @@ const putInCache = async (request, response) => { }; -const cacheAndRevalidate = async ({ request, preloadResponsePromise, fallbackUrl }) => { +const cacheAndRevalidate = async ({ request, preloadResponsePromise, fallbackUrl }: {request: Request, preloadResponsePromise: Promise, fallbackUrl: string}) => { const cache = await caches.open(cacheName); @@ -111,9 +111,7 @@ self.addEventListener('activate', (event) => { self.addEventListener('install', (event) => { console.log('[personal-sw]: installing...', event) event.waitUntil( - addResourcesToCache([ - ...(__assets ?? []) - ]) + addResourcesToCache(__assets ?? []) ); self.skipWaiting(); // activate updated SW });