2022-12-18 00:15:19 +00:00
|
|
|
import { isCI, isDevelopment } from 'std-env'
|
2022-12-17 23:29:16 +00:00
|
|
|
import type { VitePWANuxtOptions } from '../modules/pwa/types'
|
|
|
|
|
2022-12-28 14:08:03 +00:00
|
|
|
export const pwa: VitePWANuxtOptions = {
|
2022-12-17 23:29:16 +00:00
|
|
|
mode: isCI ? 'production' : 'development',
|
2022-12-21 00:06:51 +00:00
|
|
|
// disable PWA only when in preview mode
|
2022-12-22 13:48:20 +00:00
|
|
|
disable: /* temporarily test in CI isPreview || */ (isDevelopment && process.env.VITE_DEV_PWA !== 'true'),
|
2022-12-17 23:29:16 +00:00
|
|
|
scope: '/',
|
|
|
|
srcDir: './service-worker',
|
|
|
|
filename: 'sw.ts',
|
|
|
|
strategies: 'injectManifest',
|
|
|
|
injectRegister: false,
|
|
|
|
includeManifestIcons: false,
|
2023-01-06 12:48:43 +00:00
|
|
|
manifest: false,
|
2022-12-17 23:29:16 +00:00
|
|
|
injectManifest: {
|
2023-01-17 10:42:42 +00:00
|
|
|
globPatterns: ['**/*.{js,json,css,html,txt,svg,png,ico,webp,woff,woff2,ttf,eot,otf,wasm}'],
|
|
|
|
globIgnores: ['emojis/**', 'shiki/**', 'manifest**.webmanifest'],
|
2023-05-29 15:52:27 +01:00
|
|
|
manifestTransforms: [(entries) => {
|
|
|
|
const manifest = entries.map((entry) => {
|
|
|
|
if (entry.url.length > 1 && entry.url[0] !== '/')
|
|
|
|
entry.url = `/${entry.url}`
|
|
|
|
|
|
|
|
return entry
|
|
|
|
})
|
|
|
|
|
|
|
|
return { manifest, warnings: [] }
|
|
|
|
}],
|
2022-12-17 23:29:16 +00:00
|
|
|
},
|
|
|
|
devOptions: {
|
|
|
|
enabled: process.env.VITE_DEV_PWA === 'true',
|
|
|
|
type: 'module',
|
|
|
|
},
|
|
|
|
}
|