File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Deploy to GitHub Pages
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ workflow_dispatch :
8+
9+ permissions :
10+ contents : write
11+
12+ concurrency :
13+ group : gh-pages-deploy
14+ cancel-in-progress : true
15+
16+ jobs :
17+ deploy :
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - name : Checkout
22+ uses : actions/checkout@v4
23+
24+ - name : Setup Node.js
25+ uses : actions/setup-node@v4
26+ with :
27+ node-version : 20
28+ cache : npm
29+
30+ - name : Install dependencies
31+ run : npm ci
32+
33+ - name : Build
34+ run : npm run build
35+
36+ - name : Deploy to gh-pages
37+ uses : peaceiris/actions-gh-pages@v4
38+ with :
39+ github_token : ${{ secrets.GITHUB_TOKEN }}
40+ publish_dir : ./dist
Original file line number Diff line number Diff line change 66
77本项目构建产物在 ` dist/ ` ,并已内置适配 Pages 的配置(资源使用相对路径、路由使用 HashRouter)。
88
9- ### 1)本地构建并发布到 gh-pages 分支
9+ ### 1)推送代码后自动构建并发布(推荐)
1010
11- ``` bash
12- npm run build
13- npm run deploy
14- ```
15-
16- 其中 ` npm run deploy ` 会把 ` dist/ ` 发布到仓库的 ` gh-pages ` 分支。
17-
18- ### 2)在 GitHub 仓库里设置 Pages 来源
11+ 已新增 GitHub Actions 工作流:当代码 push 到 ` main ` 分支后,会自动执行构建并将 ` dist/ ` 发布到 ` gh-pages ` 分支。
12+ 工作流文件:` .github/workflows/deploy-gh-pages.yml `
1913
20- 进入仓库页面:
14+ ### 2)在 GitHub 仓库里设置 Pages 来源(首次配置)
2115
2216- Settings → Pages
2317- Build and deployment → Source 选择 ** Deploy from a branch**
2418- Branch 选择 ** ` gh-pages ` ** ,目录选择 ** ` / (root) ` ** ,保存
2519
2620稍等片刻即可通过 Pages 地址访问。
21+
22+ ### 3)手动发布(可选备用)
23+
24+ ``` bash
25+ npm run build
26+ npm run deploy
27+ ```
You can’t perform that action at this time.
0 commit comments