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 : read
11+ pages : write
12+ id-token : write
13+
14+ concurrency :
15+ group : pages
16+ cancel-in-progress : true
17+
18+ jobs :
19+ build :
20+ runs-on : ubuntu-latest
21+
22+ steps :
23+ - name : Checkout
24+ uses : actions/checkout@v4
25+
26+ - name : Setup Node.js
27+ uses : actions/setup-node@v4
28+ with :
29+ node-version : 20
30+ cache : npm
31+
32+ - name : Configure GitHub Pages
33+ uses : actions/configure-pages@v5
34+
35+ - name : Install dependencies
36+ run : npm ci
37+
38+ - name : Build site
39+ run : npm run build
40+
41+ - name : Upload Pages artifact
42+ uses : actions/upload-pages-artifact@v3
43+ with :
44+ path : ./dist
45+
46+ deploy :
47+ needs : build
48+ runs-on : ubuntu-latest
49+ environment :
50+ name : github-pages
51+ url : ${{ steps.deployment.outputs.page_url }}
52+
53+ steps :
54+ - name : Deploy to GitHub Pages
55+ id : deployment
56+ uses : actions/deploy-pages@v4
Original file line number Diff line number Diff line change @@ -19,3 +19,16 @@ npm run dev
1919``` bash
2020npm run build
2121```
22+
23+ ## 部署到 GitHub Pages
24+
25+ 仓库已包含 GitHub Actions 工作流:
26+
27+ - 推送到 ` main ` 分支后自动构建并部署
28+ - 部署产物来自 ` dist/ `
29+ - Vite 会在 GitHub Actions 中自动使用仓库名作为 Pages 基路径
30+
31+ 首次启用时需要在 GitHub 仓库设置中确认:
32+
33+ 1 . 打开 ` Settings -> Pages `
34+ 2 . 在 ` Build and deployment ` 中将 ` Source ` 设置为 ` GitHub Actions `
Original file line number Diff line number Diff line change 1414 "vue" : " ^3.5.22"
1515 },
1616 "devDependencies" : {
17+ "@types/node" : " ^24.12.2" ,
1718 "@vitejs/plugin-vue" : " ^6.0.1" ,
1819 "@vue/tsconfig" : " ^0.8.1" ,
1920 "typescript" : " ^5.9.3" ,
Original file line number Diff line number Diff line change 66 "module" : " ESNext" ,
77 "skipLibCheck" : true ,
88 "moduleResolution" : " Bundler" ,
9+ "types" : [" node" ],
910 "allowImportingTsExtensions" : true ,
1011 "resolveJsonModule" : true ,
1112 "isolatedModules" : true ,
Original file line number Diff line number Diff line change 11import { defineConfig } from 'vite'
22import vue from '@vitejs/plugin-vue'
33
4+ const repositoryName = process . env . GITHUB_REPOSITORY ?. split ( '/' ) [ 1 ]
5+ const pagesBase =
6+ process . env . GITHUB_ACTIONS === 'true' && repositoryName
7+ ? `/${ repositoryName } /`
8+ : '/'
9+
410export default defineConfig ( {
11+ base : pagesBase ,
512 plugins : [ vue ( ) ] ,
613} )
You can’t perform that action at this time.
0 commit comments