feat: add excludeRoutes option
This commit is contained in:
parent
8e4083cb01
commit
c3df8b33da
3 changed files with 18 additions and 2 deletions
|
@ -14,6 +14,9 @@ export default defineConfig({
|
|||
assetCachePrefix: 'cozy-reader',
|
||||
customRoutes: [
|
||||
'/threads'
|
||||
],
|
||||
excludeRoutes: [
|
||||
'/exclude'
|
||||
]
|
||||
})
|
||||
]
|
||||
|
|
13
index.js
13
index.js
|
@ -9,6 +9,7 @@ import { randomUUID } from "node:crypto";
|
|||
* assetCachePrefix?: string,
|
||||
* assetCacheVersionID?: string,
|
||||
* customRoutes?: Array<string>,
|
||||
* excludeRoutes?: Array<string,
|
||||
* }} ServiceWorkerConfig
|
||||
* @typedef {import('astro').AstroIntegration} AstroIntegration
|
||||
*/
|
||||
|
@ -24,7 +25,8 @@ export default function serviceWorker(config) {
|
|||
assetCachePrefix,
|
||||
assetCacheVersionID = randomUUID(),
|
||||
path: serviceWorkerPath,
|
||||
customRoutes = []
|
||||
customRoutes = [],
|
||||
excludeRoutes = []
|
||||
} = config;
|
||||
|
||||
/**
|
||||
|
@ -110,6 +112,11 @@ export default function serviceWorker(config) {
|
|||
.filter(pathname => pathname !== '')
|
||||
?? [];
|
||||
|
||||
const _excludeRoutes = [
|
||||
...excludeRoutes,
|
||||
...excludeRoutes.map(route => `${route}/`)
|
||||
];
|
||||
|
||||
assets = [...new Set([
|
||||
...assets,
|
||||
..._routes,
|
||||
|
@ -120,7 +127,9 @@ export default function serviceWorker(config) {
|
|||
])].filter(asset => !!asset
|
||||
&& asset !== ''
|
||||
&& !asset.includes('404')
|
||||
&& !asset.includes('index.html'));
|
||||
&& !asset.includes('index.html')
|
||||
&& !_excludeRoutes.includes(asset)
|
||||
);
|
||||
|
||||
console.log('[astro-sw] Assets for caching:', assets);
|
||||
|
||||
|
|
4
src/pages/exclude.astro
Normal file
4
src/pages/exclude.astro
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
---
|
||||
|
||||
exclude
|
Loading…
Reference in a new issue