Skip to content

Commit 98c46f4

Browse files
committed
修改了环境变量
1 parent ae742d4 commit 98c46f4

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,25 +336,34 @@ npm link # 本地调试
336336
- **SimApiVersion**:由 simapi 库构建时注入
337337
- **AppVersion**:不注入,留给调用方 APP 注入
338338

339+
**支持的版本号环境变量(按优先级):**
340+
341+
1. `VITE_SimApiVersion` — Vite .env 文件
342+
2. `npm_config_SimApiVersion` — npm 构建时通过 `npm run build` 前设置
343+
3. `SimApiVersion` — 直接环境变量(如 GitHub Actions)
344+
345+
未指定时默认为 `0.0.0-develop`
346+
339347
**本地构建:**
340348

341349
```bash
342-
# 通过环境变量注入 SimApiVersion
343350
# Windows PowerShell
344351
$env:npm_config_SimApiVersion='1.0.0'; npm run build
345352

353+
# Windows CMD
354+
set npm_config_SimApiVersion=1.0.0 && npm run build
355+
346356
# Linux/Mac
347357
npm_config_SimApiVersion=1.0.0 npm run build
348358
```
349359

350-
未指定时默认为 `0.0.0-develop`
351-
352-
**CI/CD 构建版本号:**
360+
**GitHub Actions / CI/CD:**
353361

354362
```yaml
355-
env:
356-
SimApiVersion: ${{ github.ref_name }}
357-
run: npm run build
363+
- name: Build
364+
env:
365+
SimApiVersion: ${{ github.ref_name }} # 或其他版本号
366+
run: npm run build
358367
```
359368
360369
**调用方注入 AppVersion:**

vite.config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ export default defineConfig(({ mode }) => {
3131
}
3232
},
3333
define: {
34-
// SimApiVersion 由环境变量注入
35-
'SimApiVersion': JSON.stringify(env.VITE_SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
34+
// SimApiVersion 由环境变量注入,支持:
35+
// - VITE_SimApiVersion (Vite .env 文件)
36+
// - npm_config_SimApiVersion (npm 构建时)
37+
// - SimApiVersion (直接环境变量,如 GitHub Actions)
38+
'SimApiVersion': JSON.stringify(
39+
env.VITE_SimApiVersion ||
40+
process.env.npm_config_SimApiVersion ||
41+
process.env.SimApiVersion ||
42+
'0.0.0-develop'
43+
),
3644
}
3745
}
3846
})

0 commit comments

Comments
 (0)