diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..c951469 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,61 @@ +name: Deploy to GitHub Pages + +on: + # 当推送到main分支时触发 + push: + branches: [ main ] + + # 允许手动触发工作流 + workflow_dispatch: + +# 设置GITHUB_TOKEN的权限以允许部署到GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# 只允许一个并发部署,跳过正在进行的运行之间的队列 +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # 构建作业 + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # 上传dist目录 + path: ./dist + + # 部署作业 + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/vite.config.ts b/vite.config.ts index bbcf80c..7153822 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,5 @@ import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], + base: process.env.NODE_ENV === 'production' ? '/obs-overlay-widget/' : '/', })