From 7088747dee1dda4af1cb8ab03334f3efff0ee0c3 Mon Sep 17 00:00:00 2001 From: yuantao Date: Mon, 3 Nov 2025 15:23:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/vite.config.js b/vite.config.js index 2e536ff..26b431a 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,20 +1,15 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { VitePWA } from 'vite-plugin-pwa' - // https://vitejs.dev/config/ export default defineConfig(({ mode }) => { const isPwaMode = mode === 'pwa' - const plugins = [vue()] - // 只在PWA模式下添加PWA插件 if (isPwaMode) { plugins.push( VitePWA({ - strategies: 'injectManifest', - srcDir: 'src', - filename: 'sw.js', + strategies: 'generateSW', registerType: 'autoUpdate', devOptions: { enabled: false, @@ -41,13 +36,23 @@ export default defineConfig(({ mode }) => { }, ], }, - injectManifest: { - globPatterns: ['**/*.{js,css,html,wasm,png,jpg,jpeg,svg,ico}'], + workbox: { + globPatterns: ['**/*.{js,css,html,ico,png,jpg,jpeg,svg,woff,woff2,ttf,eot}'], + // 预缓存我们指定的静态资源 + additionalManifestEntries: [ + { url: '/', revision: null }, + { url: '/index.html', revision: null }, + { url: '/icons/icon-192.png', revision: null }, + { url: '/icons/icon-512.png', revision: null }, + // 添加更多需要预缓存的静态资源 + { url: '/assets/icons/drawable-xxhdpi/note_background.png', revision: null }, + { url: '/assets/icons/drawable-xxhdpi/note_setting_bg.png', revision: null }, + { url: '/assets/icons/drawable-xxhdpi/action_bar_default.png', revision: null }, + ], }, }) ) } - return { plugins, resolve: {