Skip to content

Commit d6b02a4

Browse files
committed
ci(github-pages): 添加 GitHub Pages 部署工作流
新增 GitHub Pages 部署工作流配置文件,用于自动构建和部署静态内容到 GitHub Pages。配置包括设置 pnpm、Node.js 环境、安装依赖、构建项目并上传到 Pages。 feat(vite): 支持动态配置 base 路径 修改 vite.config.ts 以支持通过环境变量动态配置 base 路径,并增加构建时的 chunk 大小警告限制。
1 parent 4d5b18c commit d6b02a4

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

.github/workflows/github-pages.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 一个简单的 GitHub Pages 部署工作流
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# 仅在推送到默认分支时运行
6+
push:
7+
branches: [main]
8+
9+
# 这个选项可以使你手动在 Action tab 页面触发工作流
10+
workflow_dispatch:
11+
12+
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# 允许一个并发部署
19+
concurrency:
20+
group: pages
21+
cancel-in-progress: true
22+
23+
jobs:
24+
# 单次部署的工作描述
25+
deploy:
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v5
33+
34+
- name: Setup pnpm
35+
uses: pnpm/action-setup@v4
36+
37+
- name: Set up Node
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: lts/*
41+
cache: pnpm
42+
- name: Install dependencies
43+
run: pnpm install
44+
- name: Build
45+
run: pnpm run build
46+
env:
47+
VITE_BASE_PATH: /usb.ids/
48+
- name: Setup Pages
49+
uses: actions/configure-pages@v5
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v4
52+
with:
53+
# 上传 dist 文件夹
54+
path: ./dist
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

vite.config.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import path from 'node:path'
2-
import { defineConfig } from 'vite'
2+
import process from 'node:process'
3+
import { defineConfig, loadEnv } from 'vite'
34
import usbIdsPlugin from './plugins/plugin-usb-ids'
45

5-
export default defineConfig({
6-
plugins: [usbIdsPlugin({
7-
fallbackFile: path.resolve(__dirname, 'usb.ids.json'),
8-
skipInDev: true,
9-
})],
6+
export default defineConfig(({ command }) => {
7+
const env = loadEnv(command, process.cwd())
8+
9+
const base = env.VITE_BASE_PATH || '/'
10+
console.log('vite base ', base)
11+
12+
return {
13+
base,
14+
plugins: [
15+
usbIdsPlugin({
16+
fallbackFile: path.resolve(__dirname, 'usb.ids.json'),
17+
skipInDev: true,
18+
}),
19+
],
20+
build: {
21+
chunkSizeWarningLimit: 2048,
22+
},
23+
}
1024
})

0 commit comments

Comments
 (0)