feat: add routes to assets to be cached
This commit is contained in:
parent
bb1e215ed3
commit
43dfab5173
3 changed files with 16 additions and 2 deletions
14
index.js
14
index.js
|
@ -77,13 +77,23 @@ export default function serviceWorker(config) {
|
|||
injectScript('page', registrationScript);
|
||||
},
|
||||
'astro:build:ssr': ({ manifest }) => {
|
||||
assets = [...new Set(manifest.assets ?? [])].filter(ass => !ass.includes('sw.js'))
|
||||
assets = manifest.assets.filter(ass => !ass.includes('sw.js'))
|
||||
},
|
||||
'astro:build:done': async ({ dir }) => {
|
||||
'astro:build:done': async ({ dir, routes }) => {
|
||||
const outFile = fileURLToPath(new URL('./sw.js', dir));
|
||||
const __dirname = path.resolve(path.dirname('.'));
|
||||
const swPath = path.join(__dirname, serviceWorkerPath ?? '');
|
||||
let originalScript;
|
||||
|
||||
const _routes = routes
|
||||
.filter(({isIndex}) => isIndex)
|
||||
.map(({pathname}) => pathname)
|
||||
?? [];
|
||||
|
||||
assets = [...new Set([...assets, ..._routes])]
|
||||
|
||||
console.log('>>> assets', assets);
|
||||
|
||||
try {
|
||||
console.log('[astro-sw] Using service worker:', swPath);
|
||||
originalScript = await readFile(swPath);
|
||||
|
|
1
public/sample.asset.txt
Normal file
1
public/sample.asset.txt
Normal file
|
@ -0,0 +1 @@
|
|||
asset
|
3
src/pages/blog/index.astro
Normal file
3
src/pages/blog/index.astro
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
---
|
||||
blog index
|
Loading…
Reference in a new issue