2023-01-20 15:54:01 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import react from '@vitejs/plugin-react'
|
2023-01-23 16:57:22 +08:00
|
|
|
import { existsSync, unlinkSync } from 'fs'
|
|
|
|
|
|
|
|
const cachePath = './cache.json'
|
|
|
|
|
|
|
|
const FeedCacheHmr = () => ({
|
|
|
|
name: 'feed-cache-hmr',
|
|
|
|
enforce: 'pre' as const,
|
|
|
|
handleHotUpdate({ file }) {
|
|
|
|
// If the feeds.ts file is updated, remove the cached version
|
|
|
|
if (file.endsWith('src/feeds.ts') && existsSync(cachePath)) {
|
|
|
|
unlinkSync(cachePath)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2023-01-20 15:54:01 +08:00
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
2023-01-23 16:57:22 +08:00
|
|
|
plugins: [react(), FeedCacheHmr()],
|
2023-01-20 15:54:01 +08:00
|
|
|
})
|