From 838dff4758f52055612ae2078108ff324c138d61 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 15 Jan 2025 14:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Vite=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=BF=90=E8=A1=8C=E6=97=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=AD=96=E7=95=A5=EF=BC=8C=E7=A1=AE=E4=BF=9D=E9=9D=99?= =?UTF-8?q?=E6=80=81=E8=B5=84=E6=BA=90=E5=92=8C=E5=9B=BE=E5=83=8F=E7=9A=84?= =?UTF-8?q?=E9=AB=98=E6=95=88=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/vite.config.ts b/vite.config.ts index d1ba14e4..183a3f03 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -34,7 +34,30 @@ export default defineConfig({ filename: 'service-worker.ts', workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,jpg,jpeg}'], - navigateFallbackDenylist: [/.*\/api\/v\d+\/system\/logging.*/], + runtimeCaching: [ + { + urlPattern: /\.(?:js|css|html)$/, + handler: 'StaleWhileRevalidate', + options: { + cacheName: 'static-resources', + }, + }, + { + urlPattern: /\.(?:png|jpg|jpeg|svg|ico)$/, + handler: 'CacheFirst', + options: { + cacheName: 'image-cache', + expiration: { + maxEntries: 50, + maxAgeSeconds: 30 * 24 * 60 * 60, // 缓存 30 天 + }, + }, + }, + ], + navigateFallback: '/index.html', // 确保页面路由正确加载 + navigateFallbackDenylist: [ + /.*\/api\/v\d+\/system\/logging.*/, + ], }, injectManifest: { rollupFormat: 'iife',