auto replace cache on new deploy

This commit is contained in:
2026-04-07 10:35:50 +05:30
parent 0ca694ca99
commit 529b1bad89
3 changed files with 18 additions and 3 deletions

View File

@@ -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,