Skip to content

Commit 2ed7ffd

Browse files
committed
添加部署文件
1 parent 4010d96 commit 2ed7ffd

6 files changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ npm run dev
1919
```bash
2020
npm 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`

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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",

tsconfig.node.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"module": "ESNext",
77
"skipLibCheck": true,
88
"moduleResolution": "Bundler",
9+
"types": ["node"],
910
"allowImportingTsExtensions": true,
1011
"resolveJsonModule": true,
1112
"isolatedModules": true,

vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { defineConfig } from 'vite'
22
import 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+
410
export default defineConfig({
11+
base: pagesBase,
512
plugins: [vue()],
613
})

0 commit comments

Comments
 (0)