Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build with VitePress
env:
# 预览站点不使用 Service Worker 缓存,保证每次访问都拿到最新内容
PWA_SELF_DESTROYING: "true"
run: pnpm run build
- name: Save PR metadata
env:
Expand Down
2 changes: 2 additions & 0 deletions course/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default withPwa(
},
pwa: {
registerType: "autoUpdate",
// PR 预览构建时生成会自我注销的 Service Worker,避免评审时看到缓存的旧预览
selfDestroying: process.env.PWA_SELF_DESTROYING === "true",
manifest: {
name: title,
short_name: "Zig 圣经",
Expand Down
8 changes: 8 additions & 0 deletions course/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// .vitepress/theme/index.ts
/// <reference types="vite-plugin-pwa/client" />
import type { Theme } from "vitepress";
import DefaultTheme from "vitepress/theme";

Expand Down Expand Up @@ -28,6 +29,13 @@ export default {
details.removeAttribute("open");
});
});

// 注册 Service Worker。插件默认注入的 registerSW.js 只负责注册,新版本激活后页面不会刷新,
// 读者会继续看到预缓存的旧内容;改用 virtual:pwa-register 后,autoUpdate 模式会在新版本激活时自动刷新页面。
// 引入该模块后,插件也不再注入 registerSW.js。
import("virtual:pwa-register").then(({ registerSW }) => {
registerSW({ immediate: true });
});
}
},
Layout() {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"subset-font": "^2.9.0",
"typescript": "^7.0.2",
"vite-plugin-pwa": "^1.3.0",
"vitepress": "^1.6.4"
"vitepress": "^1.6.4",
"workbox-window": "^7.4.1"
},
"dependencies": {
"@giscus/vue": "^3.1.1"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading