Add no-cache headers to index.html via custom Vite plugin
• Create noCachePlugin for Vite • Add cache-control meta tags • Inject headers into index.html • Prevent browser caching issues
This commit is contained in:
parent
4ae44bb24b
commit
93ce53394f
1 changed files with 13 additions and 1 deletions
|
|
@ -4,9 +4,21 @@ import { webuiPrefix } from '@/lib/constants'
|
||||||
import react from '@vitejs/plugin-react-swc'
|
import react from '@vitejs/plugin-react-swc'
|
||||||
import tailwindcss from '@tailwindcss/vite'
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
|
|
||||||
|
// A custom Vite plugin to add cache-control headers to index.html
|
||||||
|
const noCachePlugin = () => ({
|
||||||
|
name: 'no-cache',
|
||||||
|
transformIndexHtml(html: string) {
|
||||||
|
const cacheControlMeta = `
|
||||||
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||||
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
|
<meta http-equiv="Expires" content="0" />`;
|
||||||
|
return html.replace('</head>', `${cacheControlMeta}\n</head>`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), tailwindcss()],
|
plugins: [react(), tailwindcss(), noCachePlugin()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src')
|
'@': path.resolve(__dirname, './src')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue