Skip to content

Commit 012b3af

Browse files
author
weilei
committed
feat(docs): 添加 Vercel 部署脚本
1 parent 35876ed commit 012b3af

File tree

7 files changed

+369
-2
lines changed

7 files changed

+369
-2
lines changed

docs/.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
paths:
7+
- 'docs/**'
8+
pull_request:
9+
branches: [main, master]
10+
paths:
11+
- 'docs/**'
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v2
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v2
23+
with:
24+
node-version: '16'
25+
cache: 'npm'
26+
cache-dependency-path: docs/package-lock.json
27+
28+
- name: Install dependencies
29+
working-directory: docs
30+
run: npm ci
31+
32+
- name: Build documentation
33+
working-directory: docs
34+
run: npm run build
35+
36+
- name: Deploy to Vercel
37+
uses: vercel/action@v1
38+
with:
39+
vercel-token: ${{ secrets.VERCEL_TOKEN }}
40+
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
41+
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
42+
working-directory: docs
43+
vercel-args: ${{ github.event_name == 'push' && '--prod' || '' }}

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vercel

docs/.vercelignore

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
*.pid.lock
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage/
15+
16+
# nyc test coverage
17+
.nyc_output
18+
19+
# Grunt intermediate storage
20+
.grunt
21+
22+
# Bower dependency directory
23+
bower_components
24+
25+
# node-waf configuration
26+
.lock-wscript
27+
28+
# Compiled binary addons
29+
build/Release
30+
31+
# Dependency directories
32+
jspm_packages/
33+
34+
# TypeScript v1 declaration files
35+
typings/
36+
37+
# Optional npm cache directory
38+
.npm
39+
40+
# Optional eslint cache
41+
.eslintcache
42+
43+
# Optional REPL history
44+
.node_repl_history
45+
46+
# Output of 'npm pack'
47+
*.tgz
48+
49+
# Yarn Integrity file
50+
.yarn-integrity
51+
52+
# dotenv environment variables file
53+
.env
54+
55+
# parcel-bundler cache
56+
.cache
57+
.parcel-cache
58+
59+
# vuepress build output
60+
src/.vuepress/dist
61+
62+
# Vercel
63+
.vercel/project.json
64+
65+
# IDE
66+
.vscode/
67+
.idea/
68+
*.swp
69+
*.swo
70+
71+
# OS
72+
.DS_Store
73+
Thumbs.db
74+
75+
# Logs
76+
logs
77+
*.log
78+
79+
# Temporary folders
80+
tmp/
81+
temp/
82+
83+
# Scripts
84+
deploy.sh

docs/README.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,151 @@ Vue.use(ElementUIX);
2222
- 基于 Element UI 2.x
2323
- 企业级 AI 聊天组件
2424
- 主题可定制
25+
26+
# Element-UI-X 文档站部署指南
27+
28+
## 自动部署到 Vercel
29+
30+
### 1. 准备工作
31+
32+
#### 1.1 安装 Vercel CLI
33+
34+
```bash
35+
npm i -g vercel
36+
```
37+
38+
#### 1.2 登录 Vercel
39+
40+
```bash
41+
vercel login
42+
```
43+
44+
### 2. 本地部署测试
45+
46+
```bash
47+
# 进入文档目录
48+
cd docs
49+
50+
# 安装依赖
51+
npm install
52+
53+
# 构建文档
54+
npm run build
55+
56+
# 本地预览
57+
vercel dev
58+
```
59+
60+
### 3. 手动部署
61+
62+
#### 3.1 预览部署
63+
64+
```bash
65+
cd docs
66+
vercel
67+
```
68+
69+
#### 3.2 生产部署
70+
71+
```bash
72+
cd docs
73+
vercel --prod
74+
```
75+
76+
### 4. 自动部署配置
77+
78+
#### 4.1 GitHub Secrets 配置
79+
80+
在 GitHub 仓库的 Settings > Secrets and variables > Actions 中添加以下密钥:
81+
82+
- `VERCEL_TOKEN`: Vercel 个人访问令牌
83+
- `VERCEL_ORG_ID`: Vercel 组织 ID
84+
- `VERCEL_PROJECT_ID`: Vercel 项目 ID
85+
86+
#### 4.2 获取 Vercel 配置信息
87+
88+
```bash
89+
# 获取 Vercel Token
90+
# 访问 https://vercel.com/account/tokens 创建新的 token
91+
92+
# 获取 Org ID 和 Project ID
93+
cd docs
94+
vercel link
95+
# 查看 .vercel/project.json 文件获取 orgId 和 projectId
96+
```
97+
98+
#### 4.3 GitHub Actions 工作流
99+
100+
工作流文件位于 `.github/workflows/deploy.yml`,会在以下情况触发:
101+
102+
- 推送到 `main``master` 分支
103+
- 修改了 `docs/``packages/element-ui-x/` 目录下的文件
104+
- 创建 Pull Request
105+
106+
### 5. 部署流程
107+
108+
1. **代码推送**: 推送代码到 GitHub
109+
2. **自动构建**: GitHub Actions 自动安装依赖并构建文档
110+
3. **自动部署**:
111+
- PR: 部署到预览环境
112+
- Main/Master: 部署到生产环境
113+
114+
### 6. 自定义域名配置
115+
116+
1. 在 Vercel 项目设置中添加自定义域名
117+
2. 配置 DNS 记录指向 Vercel
118+
3. 等待 SSL 证书自动配置
119+
120+
### 7. 环境变量
121+
122+
如果需要环境变量,可以在 Vercel 项目设置中配置:
123+
124+
- `NODE_ENV`: production
125+
- `BASE_URL`: 你的域名
126+
127+
### 8. 故障排除
128+
129+
#### 8.1 构建失败
130+
131+
- 检查依赖版本兼容性
132+
- 查看构建日志中的错误信息
133+
- 确保 Node.js 版本正确
134+
135+
#### 8.2 部署失败
136+
137+
- 检查 Vercel 配置文件
138+
- 验证输出目录路径
139+
- 确保静态资源路径正确
140+
141+
#### 8.3 访问问题
142+
143+
- 检查路由配置
144+
- 验证 SPA 重写规则
145+
- 确保资源缓存策略正确
146+
147+
## 项目结构
148+
149+
```
150+
docs/
151+
├── .github/
152+
│ └── workflows/
153+
│ └── deploy.yml # GitHub Actions 工作流
154+
├── src/
155+
│ ├── .vuepress/
156+
│ │ ├── config.js # VuePress 配置
157+
│ │ ├── dist/ # 构建输出目录
158+
│ │ └── public/ # 静态资源
159+
│ ├── components/ # 组件文档
160+
│ ├── guide/ # 指南文档
161+
│ └── README.md # 首页
162+
├── .vercelignore # Vercel 忽略文件
163+
├── vercel.json # Vercel 配置
164+
├── package.json # 项目配置
165+
└── README.md # 部署说明
166+
```
167+
168+
## 相关链接
169+
170+
- [Vercel 官方文档](https://vercel.com/docs)
171+
- [VuePress 官方文档](https://vuepress.vuejs.org/)
172+
- [GitHub Actions 文档](https://docs.github.com/en/actions)

docs/deploy.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Element-UI-X 文档部署脚本
4+
5+
set -e
6+
7+
echo "🚀 开始部署 Element-UI-X 文档..."
8+
9+
# 检查是否安装了 Vercel CLI
10+
if ! command -v vercel &> /dev/null; then
11+
echo "❌ Vercel CLI 未安装,正在安装..."
12+
npm install -g vercel
13+
fi
14+
15+
# 安装依赖
16+
echo "📦 安装依赖..."
17+
npm ci
18+
19+
# 构建文档
20+
echo "🔨 构建文档..."
21+
npm run build
22+
23+
# 检查构建结果
24+
if [ ! -d "src/.vuepress/dist" ]; then
25+
echo "❌ 构建失败,输出目录不存在"
26+
exit 1
27+
fi
28+
29+
echo "✅ 构建完成"
30+
31+
# 部署到 Vercel
32+
echo "🌐 部署到 Vercel..."
33+
34+
if [ "$1" = "prod" ] || [ "$1" = "production" ]; then
35+
echo "🚀 部署到生产环境..."
36+
vercel --prod --yes
37+
else
38+
echo "🔍 部署到预览环境..."
39+
vercel --yes
40+
fi
41+
42+
echo "✅ 部署完成!"

docs/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
{
2-
"name": "@element-x/docs",
2+
"name": "element-ui-x-docs",
33
"version": "0.1.0",
44
"private": true,
55
"description": "Element-UI-X组件库的文档站点",
66
"scripts": {
77
"dev": "vuepress dev src",
8-
"build": "vuepress build src"
8+
"build": "vuepress build src",
9+
"deploy": "bash deploy.sh",
10+
"deploy:prod": "bash deploy.sh prod",
11+
"vercel:link": "vercel link",
12+
"vercel:env": "vercel env ls",
13+
"clean": "rm -rf src/.vuepress/dist"
914
},
1015
"dependencies": {
1116
"@vuepress/plugin-active-header-links": "^1.9.10",

docs/vercel.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": 2,
3+
"name": "element-ui-x-docs",
4+
"buildCommand": "npm run build",
5+
"outputDirectory": "src/.vuepress/dist",
6+
"installCommand": "npm install",
7+
"framework": null,
8+
"rewrites": [
9+
{
10+
"source": "/(.*)",
11+
"destination": "/index.html"
12+
}
13+
],
14+
"headers": [
15+
{
16+
"source": "/(.*)",
17+
"headers": [
18+
{
19+
"key": "X-Content-Type-Options",
20+
"value": "nosniff"
21+
},
22+
{
23+
"key": "X-Frame-Options",
24+
"value": "DENY"
25+
},
26+
{
27+
"key": "X-XSS-Protection",
28+
"value": "1; mode=block"
29+
}
30+
]
31+
},
32+
{
33+
"source": "/(.*)\\.(js|css|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)",
34+
"headers": [
35+
{
36+
"key": "Cache-Control",
37+
"value": "public, max-age=31536000, immutable"
38+
}
39+
]
40+
}
41+
],
42+
"cleanUrls": true,
43+
"trailingSlash": false
44+
}

0 commit comments

Comments
 (0)