Skip to content

Commit 277a95b

Browse files
remove gh-pages dependency
1 parent e6c6dd2 commit 277a95b

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

.github/workflows/deployToGithubPages.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ jobs:
2828
node-version: 20
2929
cache: 'npm'
3030

31+
- name: Cache build output (Vite + TS)
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cache/vite
36+
~/.npm
37+
node_modules/.cache
38+
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json', 'tsconfig*.json', 'vite.config.*') }}
39+
restore-keys: |
40+
${{ runner.os }}-build-
41+
3142
- name: Install dependencies
3243
run: npm ci
3344

AI_Document.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,69 @@ if [ -f CNAME ]; then cp CNAME dist/CNAME; fi
224224
如需继续删除 `gh-pages` 依赖或添加缓存优化告诉我即可。
225225

226226
---
227+
228+
# 依赖清理与缓存优化记录 (2025-09-15)
229+
230+
## 变更概览
231+
本次调整:
232+
1. 删除 `devDependencies` 中的 `gh-pages` 依赖(已完全迁移到官方 `deploy-pages` 工作流,不再需要本地推送分支方案)。
233+
2. 修改 `package.json``deploy` 脚本:
234+
- 旧:`vite build && cp CNAME dist/CNAME && gh-pages -d dist`
235+
- 新:`npm run build && cp CNAME dist/CNAME`
236+
说明:现在部署由 GitHub Actions 完成,`deploy` 仅保留本地构建+写入 CNAME 的能力(调试 dist 用)。
237+
3.`.github/workflows/deployToGithubPages.yml` 中新增缓存步骤:
238+
```yaml
239+
- name: Cache build output (Vite + TS)
240+
uses: actions/cache@v4
241+
with:
242+
path: |
243+
~/.cache/vite
244+
~/.npm
245+
node_modules/.cache
246+
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json', 'tsconfig*.json', 'vite.config.*') }}
247+
restore-keys: |
248+
${{ runner.os }}-build-
249+
```
250+
251+
## 为什么可以安全移除 `gh-pages`
252+
当前部署链路:构建 → 上传 artifact → `actions/deploy-pages`。官方 Action 会将 artifact 发布为 Pages 版本,不需要再维护 `gh-pages` 分支,因此 `gh-pages` 包的 git push 逻辑失效。移除后:
253+
* 减少一次依赖安装体积与安全面。
254+
* 避免开发者误运行旧发布脚本导致分支状态漂移。
255+
256+
## 缓存策略说明
257+
虽然 `setup-node` 已启用 `cache: npm`,但仍追加:
258+
* `~/.cache/vite`:Vite/ESBuild/Tailwind 某些中间缓存可能命中(视版本与配置而定,命中率不保证,但成本低)。
259+
* `node_modules/.cache`:若未来引入 SWC/PostCSS 之类缓存目录可直接受益。
260+
* 同时包含 `~/.npm` 使得即便 `setup-node` 行为变更也有二级兜底(轻冗余,可视需要再精简)。
261+
262+
键设计:
263+
```
264+
${{ runner.os }}-build-${{ hashFiles('package-lock.json', 'tsconfig*.json', 'vite.config.*') }}
265+
```
266+
当依赖锁 / TS 配置 / Vite 配置变化时触发失效,保证缓存正确性。
267+
268+
## 本地影响
269+
本地开发与运行不受影响;`npm run deploy` 现在不会再试图推送 Git 分支,只用于生成 `dist` 供手动预览:
270+
```
271+
npm run deploy
272+
npx serve dist
273+
```
274+
275+
## 若需要恢复 `gh-pages` 旧方案
276+
可回滚到历史提交重新取回:
277+
1. 恢复依赖:`npm i -D gh-pages`
278+
2. 还原脚本:`"deploy": "vite build && cp CNAME dist/CNAME && gh-pages -d dist"`
279+
3. 新建(或继续使用) `gh-pages` 分支,并在 Settings → Pages 切换 Source。
280+
281+
## 后续可考虑的进一步优化
282+
1. 在缓存步骤中分离 npm 缓存与构建缓存(减少 key 变化时的完全失效)。
283+
2. 添加 `lint` 步骤保证主分支质量:
284+
```yaml
285+
- run: npm run lint --max-warnings=0
286+
```
287+
3. 增加一个 `pull_request` 触发,仅执行构建与预览(可用 Pages 预览环境)。
288+
4. 若 Tailwind 配置增多,可专门缓存 `tailwind.config.*` 参与 key 计算。
289+
290+
如需继续压缩构建时间或加入预览环境,告知即可继续调整。
291+
292+
---

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview",
11-
"deploy": "vite build && cp CNAME dist/CNAME && gh-pages -d dist"
11+
"deploy": "npm run build && cp CNAME dist/CNAME"
1212
},
1313
"dependencies": {
1414
"@radix-ui/themes": "^3.2.1",
@@ -25,7 +25,6 @@
2525
"eslint": "^9.33.0",
2626
"eslint-plugin-react-hooks": "^5.2.0",
2727
"eslint-plugin-react-refresh": "^0.4.20",
28-
"gh-pages": "^6.3.0",
2928
"globals": "^16.3.0",
3029
"typescript": "~5.8.3",
3130
"typescript-eslint": "^8.39.1",

0 commit comments

Comments
 (0)