fix(pwa): Updates zuverlässiger erkennen und veraltete Instanzen automatisch reparieren
Unabhängige version.json-Prüfung, häufigere Update-Checks und Hard Recovery beheben hängende Android-PWAs ohne manuelles Cache-Löschen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+16
-1
@@ -2,9 +2,10 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import { VitePWA } from 'vite-plugin-pwa'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { resolve, dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
@@ -19,6 +20,19 @@ function readAppVersion(): string {
|
||||
}
|
||||
}
|
||||
|
||||
function versionJsonPlugin(version: string): Plugin {
|
||||
return {
|
||||
name: 'version-json',
|
||||
writeBundle(options) {
|
||||
const outDir = options.dir ?? resolve(__dirname, 'dist')
|
||||
writeFileSync(
|
||||
resolve(outDir, 'version.json'),
|
||||
`${JSON.stringify({ version }, null, 2)}\n`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
test: {
|
||||
@@ -42,6 +56,7 @@ export default defineConfig({
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
versionJsonPlugin(readAppVersion()),
|
||||
VitePWA({
|
||||
strategies: 'injectManifest',
|
||||
srcDir: 'src',
|
||||
|
||||
Reference in New Issue
Block a user