feat: use @ayco/astro-sw esbuild minify
This commit is contained in:
parent
7de0df94b5
commit
5e85834637
4 changed files with 15 additions and 15 deletions
|
@ -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
|
||||
}
|
||||
})
|
||||
]
|
||||
});
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<any>, 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
|
||||
});
|
Loading…
Reference in a new issue