支持预发布环境构建
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 39s

This commit is contained in:
kk
2026-07-15 10:46:02 +08:00
parent 2e84a00f6e
commit 729bc3c70e
4 changed files with 44 additions and 2 deletions
+4
View File
@@ -92,11 +92,15 @@ jobs:
# 3. 安装依赖 & 构建 Uni-app (H5)
###############################################
- name: Install dependencies and Build H5
env:
DEPLOY_ENV: ${{ steps.detect.outputs.env }}
run: |
set -e
# pnpm真实路径
PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm"
echo "构建环境: DEPLOY_ENV=$DEPLOY_ENV"
# 1. 配置镜像并安装依赖
$PNPM_PATH config set registry https://registry.npmmirror.com
$PNPM_PATH install --frozen-lockfile
+16 -2
View File
@@ -1,16 +1,30 @@
/**
* 环境配置入口
* 根据编译模式自动选择 dev / prod 配置
* 根据编译模式自动选择 dev / staging / prod 配置
*
* DEPLOY_ENV 环境变量:
* - 'staging' → 预发布环境
* - 'production' → 生产环境(默认)
* - 未设置且 NODE_ENV !== 'production' → 开发环境
*/
import common from './index.js';
import dev from './dev.js';
import staging from './staging.js';
import prod from './prod.js';
// uni-app 编译时通过 define 注译 __UNI_PLATFORM__
// H5 开发模式下 process.env.NODE_ENV === 'development'
const isProd = process.env.NODE_ENV === 'production';
const deployEnv = process.env.DEPLOY_ENV;
const envConfig = isProd ? prod : dev;
let envConfig;
if (!isProd) {
envConfig = dev;
} else if (deployEnv === 'staging') {
envConfig = staging;
} else {
envConfig = prod;
}
const config = {
...common,
+20
View File
@@ -0,0 +1,20 @@
/**
* 预发布环境配置
*/
const staging = {
// 业务 API 地址(vms-api
apiBaseUrl: 'https://vmsapi.arklinksmart.cn',
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
authRedirectUri: 'https://pre-m.arklinksmart.cn/pages/auth/loading',
// 生产环境 Token 从登录流程获取,此处为空
bearerToken: '',
enableRequestLog: false,
};
export default staging;
+4
View File
@@ -26,6 +26,10 @@ function servePublicFiles() {
export default defineConfig({
plugins: [servePublicFiles(), uni()],
// 将构建时的 DEPLOY_ENV 环境变量注入到客户端代码中
define: {
'process.env.DEPLOY_ENV': JSON.stringify(process.env.DEPLOY_ENV || ''),
},
css: {
preprocessorOptions: {
scss: {