I'm trying to install AstroPWA with the lastest astro 5.9 version and the latest AstroWind template.
I've installed "@vite-pwa/astro" and in my astro.config added the following
import AstroPWA from "@vite-pwa/astro";
AstroPWA({
mode: 'development',
registerType: 'autoUpdate',
injectRegister: 'auto',
includeAssets: ['favicon.svg'],
workbox: {
navigateFallback: '/',
globDirectory: 'dist',
globPatterns: [
'**/*.{js,css,html,svg,png,ico,json,woff2}'
],
runtimeCaching: [
{
urlPattern: ({ request }) => request.destination === 'document',
handler: 'NetworkFirst',
},
{
urlPattern: ({ request }) =>
['style', 'script', 'image', 'font'].includes(request.destination),
handler: 'CacheFirst',
},
],
},
manifest: {
name: 'Name of site',
short_name: 'SHORT',
description: 'Description of site',
theme_color: '#0f172a',
background_color: '#0f172a',
display: 'standalone',
start_url: '/',
icons: [
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' }
]
},
experimental: { directoryAndTrailingSlashHandler: true }
})
]
I then created a component called ProgressiveWebApp.astro
import { pwaInfo } from 'virtual:pwa-info';
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}
<script type="module" src="/src/pwa.ts"></script>
created ReloadPrompt.astro and placed that in components
And referenced both in our Layout.astro
import ProgressiveWebApp from '@components/common/ProgressiveWebApp.astro';
<head>
.......
<ProgressiveWebApp />
</head>
<body>
<slot/>
<ReloadPrompt />
</body>
We also created our pwa.ts in the same directory
import { registerSW } from 'virtual:pwa-register';