28 lines
808 B
TypeScript
28 lines
808 B
TypeScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
// A new URL makes the browser check and stage every deployed service worker.
|
|
// The waiting worker is still activated explicitly by the user in the console.
|
|
const pwaBuildId = Date.now().toString(36)
|
|
const serviceWorkerSource = readFileSync(new URL('./pwa/control-sw.js', import.meta.url), 'utf8')
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
react(),
|
|
{
|
|
name: 'control-pwa-assets',
|
|
generateBundle() {
|
|
this.emitFile({
|
|
type: 'asset',
|
|
fileName: 'control/sw.js',
|
|
source: serviceWorkerSource.replaceAll('__PWA_BUILD_ID__', pwaBuildId),
|
|
})
|
|
},
|
|
},
|
|
],
|
|
define: {
|
|
__PWA_BUILD_ID__: JSON.stringify(pwaBuildId),
|
|
},
|
|
})
|