diff --git a/public/sw.js b/public/sw.js index bd6abf5..6aa9cb5 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,4 +1,4 @@ -const CACHE = 'gj-v1' +const CACHE = 'gj-__BUILD_TIME__' self.addEventListener('install', (e) => { e.waitUntil( diff --git a/public/vite.svg b/public/vite.svg deleted file mode 100644 index e7b8dfb..0000000 --- a/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index d4b962d..50b65ec 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,25 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' +import fs from 'fs' +import path from 'path' + +function swBuildTimePlugin() { + return { + name: 'sw-build-time', + closeBundle() { + const swPath = path.resolve(__dirname, 'dist/sw.js') + if (fs.existsSync(swPath)) { + const content = fs.readFileSync(swPath, 'utf-8') + const timestamp = Date.now().toString() + fs.writeFileSync(swPath, content.replace('__BUILD_TIME__', timestamp)) + } + }, + } +} // https://vite.dev/config/ export default defineConfig({ - plugins: [react()], + plugins: [react(), swBuildTimePlugin()], server: { port: 8000, strictPort: false,