proper productionize project
This commit is contained in:
@@ -1,3 +1,27 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
export default defineConfig({ plugins: [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),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user