feat: 更新 Service Worker 版本管理,优化缓存策略,增加未处理更新的提示
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 15s
Docker Build & Deploy / Deploy to Production (push) Successful in 9s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s

This commit is contained in:
孙诚
2026-01-07 16:07:56 +08:00
parent 1bd6b688c1
commit c95aa6b17b
3 changed files with 50 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
import { fileURLToPath, URL } from 'node:url'
import { writeFileSync, readFileSync, existsSync } from 'node:fs'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
@@ -9,6 +11,20 @@ export default defineConfig({
plugins: [
vue(),
vueDevTools(),
{
name: 'update-sw-version',
apply: 'build',
closeBundle() {
const swPath = resolve(fileURLToPath(new URL('.', import.meta.url)), 'dist/service-worker.js')
if (existsSync(swPath)) {
let content = readFileSync(swPath, 'utf8')
const timestamp = new Date().toISOString()
content = content.replace(/const VERSION = '.*';/, `const VERSION = '${timestamp}';`)
writeFileSync(swPath, content)
console.log(`[SW Update] Version updated to ${timestamp}`)
}
}
}
],
resolve: {
alias: {