From 306ed9a5272cc440a0e01b125462d6cd2b3bbd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 9 Sep 2025 23:09:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ci:=20=E6=9B=B4=E6=96=B0=20Playwright=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BB=A5=E4=BD=BF=E7=94=A8=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 baseURL 固定为 http://localhost:4173,不再根据环境变量区分 CI 和本地环境 - 修改启动命令为先构建再启动预览服务器 - 设置 reuseExistingServer 为 true,优化服务器重用逻辑 (cherry picked from commit df6ffb99c8123dbc8b3821f2d24c19844f8554a5) --- playwright.config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 17e759d..d267d8b 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,7 +2,7 @@ import { defineConfig, devices } from '@playwright/test' import process from 'node:process' // const runningInVSCode = process.env.TERM_PROGRAM === 'vscode' -const baseURL = process.env.CI ? 'http://localhost:4173' : 'http://localhost:4730' +const baseURL = 'http://localhost:4173' /** * Read environment variables from file. @@ -106,8 +106,8 @@ export default defineConfig({ * Use the preview server on CI for more realistic testing. * Playwright will re-use the local server if there is already a dev-server running. */ - command: process.env.CI ? 'pnpm run preview' : 'pnpm run dev', + command: 'pnpm run build-only; pnpm run preview', port: Number(new URL(baseURL).port), - reuseExistingServer: !process.env.CI, + reuseExistingServer: true /* !process.env.CI */, }, }) From 87e701042f98d7ef12747a0341edc0f269932549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 9 Sep 2025 23:22:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96=20GitHub=20Actions?= =?UTF-8?q?=20=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 ++ .github/workflows/ci-cd.yaml | 3 +++ vite.config.ts | 13 +++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.env b/.env index d636bca..5bbf10a 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ +VITE_BASE=/ +VITE_BUILD_SOURCE_MAP=true VITE_BUILD_COMMIT= VITE_BUILD_TIME= diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml index 326a932..50ded36 100644 --- a/.github/workflows/ci-cd.yaml +++ b/.github/workflows/ci-cd.yaml @@ -28,6 +28,9 @@ jobs: env: VITE_BUILD_COMMIT: ${{ github.sha }} + - name: 🧪 单元测试 + run: pnpm run test:unit + - name: 📊 计算构建大小 run: | echo "📊 构建大小统计:" diff --git a/vite.config.ts b/vite.config.ts index 8f39d90..a751586 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,18 +1,19 @@ import { fileURLToPath, URL } from 'node:url' import { createViteProxy } from 'utils4u/vite' -import { defineConfig, type DepOptimizationOptions } from 'vite' +import { defineConfig, loadEnv, type DepOptimizationOptions } from 'vite' import { Plugins } from './vite.config.plugins' -// import { createRolldownSplitChunks } from './vite.config.rolldown.split-chunks' // https://vite.dev/config/ -export default defineConfig(({ command /* mode */ }) => { +export default defineConfig(({ command, mode }) => { const isBuild = command === 'build' - // const env = loadEnv(mode, process.cwd()) + const env = loadEnv(mode, process.cwd()) return { - // build: createRolldownSplitChunks(), - // base: env.VITE_BASE, + base: env.VITE_BASE, + build: { + sourcemap: env.VITE_BUILD_SOURCE_MAP === 'true', + }, plugins: Plugins(), resolve: { alias: {