32 lines
732 B
TypeScript
32 lines
732 B
TypeScript
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(), swBuildTimePlugin()],
|
|
server: {
|
|
port: 8000,
|
|
strictPort: false,
|
|
},
|
|
optimizeDeps: {
|
|
include: ['libsodium-wrappers'],
|
|
},
|
|
})
|
|
|