From 98c46f4a7b001719645349d557eb795ebbd84040 Mon Sep 17 00:00:00 2001 From: xRain Date: Wed, 8 Apr 2026 02:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++++++++++++++++------- vite.config.ts | 12 ++++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2e7a211..9c20193 100644 --- a/README.md +++ b/README.md @@ -336,25 +336,34 @@ npm link # 本地调试 - **SimApiVersion**:由 simapi 库构建时注入 - **AppVersion**:不注入,留给调用方 APP 注入 +**支持的版本号环境变量(按优先级):** + +1. `VITE_SimApiVersion` — Vite .env 文件 +2. `npm_config_SimApiVersion` — npm 构建时通过 `npm run build` 前设置 +3. `SimApiVersion` — 直接环境变量(如 GitHub Actions) + +未指定时默认为 `0.0.0-develop`。 + **本地构建:** ```bash -# 通过环境变量注入 SimApiVersion # Windows PowerShell $env:npm_config_SimApiVersion='1.0.0'; npm run build +# Windows CMD +set npm_config_SimApiVersion=1.0.0 && npm run build + # Linux/Mac npm_config_SimApiVersion=1.0.0 npm run build ``` -未指定时默认为 `0.0.0-develop`。 - -**CI/CD 构建版本号:** +**GitHub Actions / CI/CD:** ```yaml -env: - SimApiVersion: ${{ github.ref_name }} -run: npm run build +- name: Build + env: + SimApiVersion: ${{ github.ref_name }} # 或其他版本号 + run: npm run build ``` **调用方注入 AppVersion:** diff --git a/vite.config.ts b/vite.config.ts index 6cb9b5c..f3c7804 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -31,8 +31,16 @@ export default defineConfig(({ mode }) => { } }, define: { - // SimApiVersion 由环境变量注入 - 'SimApiVersion': JSON.stringify(env.VITE_SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'), + // SimApiVersion 由环境变量注入,支持: + // - VITE_SimApiVersion (Vite .env 文件) + // - npm_config_SimApiVersion (npm 构建时) + // - SimApiVersion (直接环境变量,如 GitHub Actions) + 'SimApiVersion': JSON.stringify( + env.VITE_SimApiVersion || + process.env.npm_config_SimApiVersion || + process.env.SimApiVersion || + '0.0.0-develop' + ), } } })