Skip to content

Commit 90ba3e9

Browse files
author
starle
committed
deploy
1 parent 2a243a0 commit 90ba3e9

File tree

6 files changed

+140
-36
lines changed

6 files changed

+140
-36
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Vue项目构建并部署到GitHub Pages
2+
name: Build and Deploy Vue App to Pages
3+
4+
on:
5+
# 在main分支有推送时触发
6+
push:
7+
branches: ["main"]
8+
9+
# 允许从Actions标签页手动触发
10+
workflow_dispatch:
11+
12+
# 设置GITHUB_TOKEN权限以允许部署到GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# 允许一次并发部署,跳过正在运行的部署之间排队的运行
19+
# 但不取消进行中的运行,因为我们希望允许这些生产部署完成
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
# 构建和部署作业
26+
build-and-deploy:
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: 检出代码
33+
uses: actions/checkout@v4
34+
35+
- name: 设置Node.js环境
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: '18'
39+
cache: 'npm'
40+
41+
# 改进的缓存策略
42+
- name: 缓存依赖
43+
uses: actions/cache@v3
44+
with:
45+
path: |
46+
**/node_modules
47+
~/.npm
48+
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
49+
restore-keys: |
50+
${{ runner.os }}-npm-
51+
52+
- name: 安装依赖
53+
run: npm ci
54+
55+
# 添加一个环境变量,确保基本URL配置正确
56+
- name: 构建项目
57+
run: npm run build:demo
58+
env:
59+
BASE_URL: /${{ github.event.repository.name }}/
60+
61+
- name: 创建.nojekyll文件
62+
run: |
63+
touch dist/.nojekyll
64+
65+
- name: 设置GitHub Pages
66+
uses: actions/configure-pages@v5
67+
68+
- name: 上传构建产物
69+
uses: actions/upload-pages-artifact@v3
70+
with:
71+
# 上传dist目录(Vue项目构建输出)
72+
path: './dist'
73+
74+
- name: 部署到GitHub Pages
75+
id: deployment
76+
uses: actions/deploy-pages@v4
77+
78+
- name: 部署结果通知
79+
if: always()
80+
run: |
81+
echo "部署结果: ${{ job.status }}"
82+
echo "部署URL: ${{ steps.deployment.outputs.page_url }}"

.github/workflows/npm-publish-github-packages.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,27 @@ const sku = ref([])
227227
</script>
228228
```
229229

230+
## 在线演示
231+
232+
访问我们的GitHub Pages以查看在线演示:[https://vue3-sku-form.github.io](https://vue3-sku-form.github.io)
233+
234+
## 部署说明
235+
236+
本项目使用GitHub Actions自动部署到GitHub Pages。每次推送到main分支时,都会触发构建和部署流程。
237+
238+
如果您想自行部署,可以执行以下步骤:
239+
240+
```bash
241+
# 安装依赖
242+
npm install
243+
244+
# 构建项目
245+
npm run build
246+
247+
# 部署(需要先配置好GitHub Pages)
248+
# 您可以使用GitHub Actions或手动部署dist目录
249+
```
250+
230251
## 开发
231252

232253
```bash

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"dev": "vite",
4747
"preview": "vite preview",
4848
"build": "vite build",
49+
"build:demo": "vite build --config vite.config.demo.js",
4950
"lint": "eslint --ext .js,.vue src",
5051
"prepublishOnly": "npm run build"
5152
},

vite.config.demo.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { defineConfig } from 'vite'
2+
import vue from '@vitejs/plugin-vue'
3+
import path from 'path'
4+
5+
// 从环境变量获取基本URL或使用默认值
6+
const base = process.env.BASE_URL || '/'
7+
8+
export default defineConfig({
9+
plugins: [vue()],
10+
base, // 设置基本公共路径
11+
resolve: {
12+
alias: {
13+
'@': path.resolve(__dirname, 'src')
14+
}
15+
},
16+
build: {
17+
outDir: 'dist',
18+
emptyOutDir: true,
19+
rollupOptions: {
20+
input: {
21+
main: path.resolve(__dirname, 'index.html'),
22+
},
23+
}
24+
},
25+
css: {
26+
preprocessorOptions: {
27+
scss: {
28+
additionalData: `@use "sass:math";`
29+
}
30+
}
31+
}
32+
})

vite.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
33
import path from 'path'
44

5+
// 从环境变量获取基本URL或使用默认值
6+
const base = process.env.BASE_URL || '/'
7+
58
export default defineConfig({
69
plugins: [vue()],
10+
base, // 设置基本公共路径
711
resolve: {
812
alias: {
913
'@': path.resolve(__dirname, 'src')

0 commit comments

Comments
 (0)