Skip to content

Commit 1b7d03e

Browse files
committed
添加GitHub Pages部署配置:1.增加npm deploy命令 2.配置GitHub Actions自动部署工作流
1 parent c16061c commit 1b7d03e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.github/workflows/deploy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 部署到GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pages: write
11+
id-token: write
12+
13+
jobs:
14+
build-and-deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 检出代码
18+
uses: actions/checkout@v4
19+
20+
- name: 设置Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '18'
24+
cache: 'npm'
25+
26+
- name: 安装依赖
27+
run: npm ci
28+
29+
- name: 构建
30+
run: npm run build
31+
32+
- name: 部署到GitHub Pages
33+
uses: JamesIves/github-pages-deploy-action@v4
34+
with:
35+
folder: dist
36+
branch: gh-pages
37+
clean: true

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"dev": "vite",
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
10-
"preview": "vite preview"
10+
"preview": "vite preview",
11+
"predeploy": "npm run build",
12+
"deploy": "gh-pages -d dist"
1113
},
1214
"dependencies": {
1315
"@iconify/icons-carbon": "^1.2.20",
@@ -32,6 +34,7 @@
3234
"eslint": "^9.21.0",
3335
"eslint-plugin-react-hooks": "^5.1.0",
3436
"eslint-plugin-react-refresh": "^0.4.19",
37+
"gh-pages": "^6.1.1",
3538
"globals": "^15.15.0",
3639
"typescript": "~5.7.2",
3740
"typescript-eslint": "^8.24.1",

0 commit comments

Comments
 (0)