auto replace cache on new deploy
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user