Skip to content

Commit 4c63371

Browse files
authored
fix(docs): fallback vitepress base to repo path in production (#438)
1 parent f52451c commit 4c63371

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

docs/.vitepress/config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ const whiteBookSidebar = generateWhiteBookSidebar()
1111
/**
1212
* Base URL 配置
1313
* - 开发环境:使用 '/'
14-
* - GitHub Pages:使用 '/KeyApp/'(通过 CI 环境变量设置
15-
* - 自定义部署:通过 VITEPRESS_BASE 环境变量设置
14+
* - 生产构建:默认使用 '/KeyApp/'(避免 GitHub Pages 资源路径丢失仓库前缀
15+
* - 自定义部署:通过 VITEPRESS_BASE 环境变量覆盖
1616
*
1717
* 注意:VitePress 的 Vue Router 需要绝对路径 base,不能用 './'
1818
*/
19-
const base = process.env.VITEPRESS_BASE ?? '/'
19+
const githubRepoFromEnv = process.env.GITHUB_REPOSITORY?.split('/')[1] ?? GITHUB_REPO
20+
const defaultBase = process.env.NODE_ENV === 'production' ? `/${githubRepoFromEnv}/` : '/'
21+
const base = process.env.VITEPRESS_BASE ?? defaultBase
2022

2123
export default defineConfig({
2224
title: 'BFM Pay',

0 commit comments

Comments
 (0)