feat: support runtime frontend configuration (#1135)

This commit is contained in:
Dream Hunter
2026-09-05 00:15:38 +08:00
committed by GitHub
parent 806ec1aeab
commit fc363cc9c5
22 changed files with 364 additions and 72 deletions
@@ -1,17 +1,17 @@
# 给网页增加 Google Ads
## 命令行部署
Google Ads 使用以下两个变量,具体值请参考 [Google AdSense](https://www.google.com/adsense/start/)
修改 `.env.prod` 文件
增加下列两个变量, 具体的值请参考 [Google AdSense](https://www.google.com/adsense/start/) 的说明
```txt
```ini
VITE_GOOGLE_AD_CLIENT=ca-pub-123456
VITE_GOOGLE_AD_SLOT=123456
```
然后执行下列命令, 重新部署 pages 即可.
任意一个变量为空时都不会加载广告。变量类型和默认值请查看 [前端变量说明](/zh/guide/frontend-vars)。
## CLI 部署
`frontend/.env.prod` 中添加上述两个变量,然后重新构建并部署:
```bash
pnpm build --emptyOutDir
@@ -19,11 +19,25 @@ pnpm build --emptyOutDir
pnpm run deploy
```
## GitHub Action 部署
完整步骤请查看 [CLI 部署前端](/zh/guide/cli/pages)。
修改 `FRONTEND_ENV`, 增加下列两个变量, 具体的值请参考 [Google AdSense](https://www.google.com/adsense/start/) 的说明, 重新部署 pages 即可.
## GitHub Actions 部署
```txt
VITE_GOOGLE_AD_CLIENT=ca-pub-123456
VITE_GOOGLE_AD_SLOT=123456
在已有的 `FRONTEND_ENV` Secret 中添加上述两个变量,然后重新运行 `Deploy Frontend` workflow。
完整步骤请查看 [GitHub Actions 部署](/zh/guide/actions/github-action)。
## 手动 ZIP 部署
编辑压缩包中 `index.html``app-config`,使用不带 `VITE_` 前缀的字段名:
```html
<script id="app-config" type="application/json">
{
"GOOGLE_AD_CLIENT": "ca-pub-123456",
"GOOGLE_AD_SLOT": "123456"
}
</script>
```
完整步骤请查看 [手动 ZIP 部署](/zh/guide/ui/pages)。