Ver código fonte

fix: 修复Web部署构建脚本环境变量传递问题

- 在 h5_for_production.js 中将环境变量逻辑从 || 改为 ?? 运算符
- 修复无法传递空字符串作为 TARO_API_URL 的问题
- 在 build-web-deployment.yml 中改用 h5_for_production.js 构建
- 添加 TARO_API_URL 和 TARO_MQTT_URL 环境变量配置
- 支持 Nginx 代理模式下的相对路径配置

改动文件:
- .build/h5_for_production.js
- .github/workflows/build-web-deployment.yml
dengdx 21 horas atrás
pai
commit
d2634c9e76

+ 3 - 2
.build/h5_for_production.js

@@ -5,8 +5,9 @@ const path = require('path');
 const fs = require('fs');
 
 // 优先使用环境变量,如果不存在则使用默认值(支持部署后可配置)
-const TARO_API_URL = process.env.TARO_API_URL || 'http://localhost:6001';
-const TARO_MQTT_URL = process.env.TARO_MQTT_URL || 'ws://localhost:8083/mqtt';
+// 使用 ?? 运算符,只在 undefined/null 时使用默认值,允许空字符串
+const TARO_API_URL = process.env.TARO_API_URL ?? 'http://localhost:6001';
+const TARO_MQTT_URL = process.env.TARO_MQTT_URL ?? 'ws://localhost:8083/mqtt';
 const rootDir = path.join(__dirname, '..');          // 项目根目录
 
 try {

+ 6 - 3
.github/workflows/build-web-deployment.yml

@@ -41,14 +41,17 @@ jobs:
         shell: powershell
         env:
           GH_TOKEN: ${{ secrets.GH_TOKEN }}
+          TARO_API_URL: ''
+          TARO_MQTT_URL: '/mqtt'
         run: |
           Write-Host "🌐 Web 部署模式 (Nginx 代理)"
-          Write-Host "   使用 h5_for_webserver.build.js 构建脚本"
-          Write-Host "   API URL: 空 (前端自行构建,nginx根据路径转发)"
+          Write-Host "   使用 h5_for_production.js 构建脚本"
+          Write-Host "   API URL: 空字符串 (nginx根据路径转发)"
+          Write-Host "   MQTT URL: /mqtt (nginx代理转发)"
           Write-Host ""
           Write-Host "当前操作系统平台: Windows"
           Write-Host "当前CPU架构: $env:PROCESSOR_ARCHITECTURE"
-          node .build/h5_for_webserver.build.js
+          node .build/h5_for_production.js
 
       - name: 部署到服务器
         env: