From 65de7f26840e1e84962f99cc0a55eac7a63769be Mon Sep 17 00:00:00 2001 From: zyronon Date: Sun, 17 Aug 2025 18:43:30 +0800 Subject: [PATCH] fix:change ci --- .github/workflows/deploy-aliyun-oss.yml | 50 +++++++++++++++++++++++++ .github/workflows/deploy-pages.yml | 11 +----- package.json | 2 +- vite.config.ts | 16 ++++---- 4 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/deploy-aliyun-oss.yml diff --git a/.github/workflows/deploy-aliyun-oss.yml b/.github/workflows/deploy-aliyun-oss.yml new file mode 100644 index 00000000..5a20852f --- /dev/null +++ b/.github/workflows/deploy-aliyun-oss.yml @@ -0,0 +1,50 @@ +name: Deploy to GitHub Pages & Aliyun OSS + +on: + push: + branches: [ 'master' ] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: 'deploy' + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + outputs: + build-path: dist + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 8 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 24 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm run build + + - name: Deploy to OSS + Refresh CDN + run: pnpm run deploy-oss + env: + OSS_KEY_ID: ${{ secrets.OSS_KEY_ID }} + OSS_KEY_SECRET: ${{ secrets.OSS_KEY_SECRET }} + OSS_BUCKET: ${{ secrets.OSS_BUCKET }} + OSS_REGION: ${{ secrets.OSS_REGION }} + CDN_DOMAIN: ${{ secrets.CDN_DOMAIN }} diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 163751f9..1fa9d59a 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -38,16 +38,7 @@ jobs: run: pnpm install - name: Build - run: pnpm run build - - - name: Deploy to OSS + Refresh CDN - run: pnpm run deploy-oss - env: - OSS_KEY_ID: ${{ secrets.OSS_KEY_ID }} - OSS_KEY_SECRET: ${{ secrets.OSS_KEY_SECRET }} - OSS_BUCKET: ${{ secrets.OSS_BUCKET }} - OSS_REGION: ${{ secrets.OSS_REGION }} - CDN_DOMAIN: ${{ secrets.CDN_DOMAIN }} + run: pnpm run build-nocdn - name: Upload artifact uses: actions/upload-pages-artifact@v3 diff --git a/package.json b/package.json index e4178a3c..6e798bf4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "vite", "test": "", "build": "vite build", - "build-local": "vite build", + "build-nocdn": "vite build", "build-tsc": "vue-tsc && vite build", "report": "vite build", "preview": "vite preview", diff --git a/vite.config.ts b/vite.config.ts index 8f9d8646..d52e6290 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -17,7 +17,7 @@ function pathResolve(dir: string) { } const lifecycle = process.env.npm_lifecycle_event; -let isBuild = ['build', 'report'].includes(lifecycle) +let isCdnBuild = ['build', 'report'].includes(lifecycle) // https://vitejs.dev/config/ export default defineConfig(() => { @@ -56,7 +56,7 @@ export default defineConfig(() => { open: true //如果存在本地服务端口,将在打包后自动展示 }) : null, SlidePlugin(), - isBuild ? [ + isCdnBuild ? [ //这里不要用vite-plugin-cdn-import,他里面使用了rollup-plugin-external-globals插件,会导致自动加载components.d.ts里面的组件全部没引入,也不报错 { name: 'inject-cdn-head', @@ -80,11 +80,11 @@ export default defineConfig(() => { build: { rollupOptions: { // 因为已经把包复制过来了,里面的axios实例用的项目的,所以这行代码可以不要了 - // external: isBuild ? ['axios'] : [],// 使用全局的 axios。因为百度翻译库内部用了0.19版本的axios,会被打包到代码里面 + // external: isCdnBuild ? ['axios'] : [],// 使用全局的 axios。因为百度翻译库内部用了0.19版本的axios,会被打包到代码里面 output: { manualChunks(id) { - if (id.includes('dialog')) { - return 'dialog' + if (id.includes('node_modules/@iconify') || id.includes('~icons')) { + return 'icons'; } if (id.includes('utils') || id.includes('hooks') @@ -93,8 +93,10 @@ export default defineConfig(() => { ) { return 'utils' } - if (id.includes('node_modules/@iconify') || id.includes('~icons')) { - return 'icons'; + if (!isCdnBuild) return + //不知为何不引入cdn之后,这里分包会报错 + if (id.includes('dialog')) { + return 'dialog' } } }