Files
EmailBill/Web/vite.config.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-12-25 11:20:56 +08:00
import { fileURLToPath, URL } from 'node:url'
import { writeFileSync, readFileSync, existsSync } from 'node:fs'
import { resolve } from 'node:path'
2025-12-25 11:20:56 +08:00
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
{
name: 'update-sw-version',
apply: 'build',
2026-01-16 11:15:44 +08:00
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}`)
}
}
}
2025-12-25 11:20:56 +08:00
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
2026-01-16 11:15:44 +08:00
}
2025-12-25 11:20:56 +08:00
},
2025-12-25 14:15:43 +08:00
build: {
// 确保 Service Worker 和 manifest 被正确复制
rollupOptions: {
input: {
main: fileURLToPath(new URL('./index.html', import.meta.url))
}
}
},
server: {
headers: {
// 允许 Service Worker 在开发环境中工作
'Service-Worker-Allowed': '/'
}
}
2025-12-25 11:20:56 +08:00
})