PWA注册改为异步避免影响加载速度

This commit is contained in:
eoao
2025-09-05 17:26:08 +08:00
parent 25a27ec038
commit 2c6803475b
3 changed files with 6 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="theme-color" content="#D3E3FD" id="theme-color-meta"> <meta name="theme-color" content="#F1F1F1" id="theme-color-meta">
<title></title> <title></title>
<link rel="icon" href="./public/mail.png" type="image/png"> <link rel="icon" href="./public/mail.png" type="image/png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
@@ -16,7 +16,7 @@
root.setAttribute('class', uiStore.dark ? 'dark' : ''); root.setAttribute('class', uiStore.dark ? 'dark' : '');
const metaTag = document.getElementById('theme-color-meta'); const metaTag = document.getElementById('theme-color-meta');
const isMobile = !window.matchMedia("(pointer: fine) and (hover: hover)").matches; const isMobile = !window.matchMedia("(pointer: fine) and (hover: hover)").matches;
metaTag.setAttribute('content', uiStore.dark ? (isMobile ? '#141414' : '#000000') : (isMobile ? '#FFFFFF' : '#D3E3FD')); metaTag.setAttribute('content', uiStore.dark ? (isMobile ? '#141414' : '#000000') : (isMobile ? '#FFFFFF' : '#F1F1F1'));
} }
</script> </script>
</head> </head>

View File

@@ -231,7 +231,7 @@ function switchDark(nextIsDark, root) {
root.setAttribute('class', nextIsDark ? 'dark' : '') root.setAttribute('class', nextIsDark ? 'dark' : '')
const metaTag = document.getElementById('theme-color-meta'); const metaTag = document.getElementById('theme-color-meta');
const isMobile = !window.matchMedia("(pointer: fine) and (hover: hover)").matches; const isMobile = !window.matchMedia("(pointer: fine) and (hover: hover)").matches;
metaTag.setAttribute('content', nextIsDark ? (isMobile ? '#141414' : '#000000') : (isMobile ? '#FFFFFF' : '#D3E3FD')); metaTag.setAttribute('content', nextIsDark ? (isMobile ? '#141414' : '#000000') : (isMobile ? '#FFFFFF' : '#F1F1F1'));
uiStore.dark = nextIsDark uiStore.dark = nextIsDark
} }

View File

@@ -17,8 +17,7 @@ export default defineConfig(({mode}) => {
base: env.VITE_STATIC_URL || '/', base: env.VITE_STATIC_URL || '/',
plugins: [vue(), plugins: [vue(),
VitePWA({ VitePWA({
registerType: 'autoUpdate', // 配置 service worker 的注册方式 injectRegister: 'script-defer',
includeAssets: ['favicon.svg', 'robots.txt'], // 指定需要包含的静态资源
manifest: { manifest: {
name: env.VITE_PWA_NAME, name: env.VITE_PWA_NAME,
short_name: env.VITE_PWA_NAME, short_name: env.VITE_PWA_NAME,
@@ -26,19 +25,13 @@ export default defineConfig(({mode}) => {
theme_color: '#FFFFFF', theme_color: '#FFFFFF',
icons: [ icons: [
{ {
src: 'mail-pwa.png',//像素尺寸一定要对应 src: 'mail-pwa.png',
sizes: '192x192', sizes: '192x192',
type: 'image/png', type: 'image/png',
} }
], ],
}, },
workbox: { workbox: false
disableDevLogs: true,
globPatterns: [],
runtimeCaching: [],
navigateFallback: null,
cleanupOutdatedCaches: true,
}
}), }),
AutoImport({ AutoImport({
resolvers: [ElementPlusResolver()], resolvers: [ElementPlusResolver()],