35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/**
|
|
* Vite build configuration and PWA asset emission.
|
|
*
|
|
* The same per-build identifier is compiled into the browser bundle and the
|
|
* service worker. This makes an hourly/visibility update check discover a new
|
|
* deployment while still leaving activation under explicit user control.
|
|
*/
|
|
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),
|
|
},
|
|
})
|