feat: don't include index.html
This commit is contained in:
parent
93eaec2a38
commit
0e29dfbf15
1 changed files with 20 additions and 18 deletions
24
index.js
24
index.js
|
@ -65,7 +65,7 @@ export default function serviceWorker(config) {
|
|||
return {
|
||||
'name': 'astro-sw',
|
||||
'hooks': {
|
||||
'astro:config:setup': ({injectScript, config}) => {
|
||||
'astro:config:setup': ({ injectScript, config }) => {
|
||||
output = config.output;
|
||||
injectScript('page', registrationScript);
|
||||
},
|
||||
|
@ -83,28 +83,28 @@ export default function serviceWorker(config) {
|
|||
const swPath = path.join(__dirname, serviceWorkerPath ?? '');
|
||||
let originalScript;
|
||||
|
||||
const _publicFiles = (await readdir(dir, {withFileTypes: true}) ?? [])
|
||||
const _publicFiles = (await readdir(dir, { withFileTypes: true }) ?? [])
|
||||
.filter(dirent => dirent.isFile())
|
||||
.map(dirent => `/${dirent.name}`);
|
||||
|
||||
const _routes = routes
|
||||
.filter(({isIndex}) => isIndex)
|
||||
.map(({pathname}) => pathname)
|
||||
.filter(({ isIndex }) => isIndex)
|
||||
.map(({ pathname }) => pathname)
|
||||
.filter(pathname => pathname !== '')
|
||||
?? [];
|
||||
|
||||
const _pages = pages
|
||||
.filter(({pathname}) => pathname !== '')
|
||||
.map(({pathname}) => `/${pathname}`)
|
||||
.filter(({ pathname }) => pathname !== '')
|
||||
.map(({ pathname }) => `/${pathname}`)
|
||||
?? [];
|
||||
|
||||
const _pagesWithoutEndSlash = pages
|
||||
.filter(({pathname}) => pathname !== '')
|
||||
.map(({pathname}) => {
|
||||
.filter(({ pathname }) => pathname !== '')
|
||||
.map(({ pathname }) => {
|
||||
const lastChar = pathname.slice(-1);
|
||||
const len = pathname.length;
|
||||
return lastChar === '/'
|
||||
? `/${pathname.slice(0, len-1)}`
|
||||
? `/${pathname.slice(0, len - 1)}`
|
||||
: `/${pathname}`;
|
||||
})
|
||||
.filter(pathname => pathname !== '')
|
||||
|
@ -117,8 +117,10 @@ export default function serviceWorker(config) {
|
|||
..._pagesWithoutEndSlash,
|
||||
...customRoutes,
|
||||
..._publicFiles
|
||||
])]
|
||||
.filter(asset => !!asset && asset !== '' && !asset.includes('404'));
|
||||
])].filter(asset => !!asset
|
||||
&& asset !== ''
|
||||
&& !asset.includes('404')
|
||||
&& !asset.includes('index.html'));
|
||||
|
||||
console.log('[astro-sw] Assets for caching:', assets);
|
||||
|
||||
|
|
Loading…
Reference in a new issue