Fix PWA install by registering service worker in theme

VitePress did not auto-inject SW registration; manual registerSW enables true app install on HTTPS.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-05 17:47:57 +08:00
parent f663867a25
commit c9f78ef25f
3 changed files with 31 additions and 1 deletions
+2 -1
View File
@@ -3,7 +3,7 @@ import { VitePWA } from 'vite-plugin-pwa'
export function createPwaPlugin() {
return VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
injectRegister: null,
manifestFilename: 'site.webmanifest',
includeAssets: [
'favicon.ico',
@@ -14,6 +14,7 @@ export function createPwaPlugin() {
'icon-512.png',
],
manifest: {
id: '/',
name: '道德经 · 传统文化典籍',
short_name: '道德经',
description: '传统文化典籍资料库',
+6
View File
@@ -2,6 +2,12 @@ import DefaultTheme from 'vitepress/theme'
import { h } from 'vue'
import InstallApp from './InstallApp.vue'
if (typeof window !== 'undefined') {
import('virtual:pwa-register').then(({ registerSW }) => {
registerSW({ immediate: true })
})
}
export default {
extends: DefaultTheme,
Layout: () => {