s***@outlook.com
s***@outlook.com
  • 发布:2023-12-28 14:29
  • 更新:2023-12-28 18:01
  • 阅读:306

【报Bug】uni-cli打包wgt包自定义环境变量在nvue页面会报undefined,vue页面正常

分类:uni小程序sdk

产品分类: uni小程序SDK

手机系统: 全部

手机厂商: 华为

页面类型: nvue

SDK版本号: 3.8.7.20230703

测试过的手机:

华为P50pro

示例代码:

package.json依赖内容

"dependencies": {  
    "@dcloudio/uni-app": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-app-plus": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-h5": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-i18n": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-360": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-alipay": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-baidu": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-jd": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-kuaishou": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-lark": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-qq": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-toutiao": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-vue": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-weixin": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-mp-xhs": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-quickapp-native": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-quickapp-webview": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-stacktracey": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-stat": "^2.0.2-3090820231124001",  
    "@vue/shared": "^3.0.0",  
    "core-js": "^3.8.3",  
    "flyio": "^0.6.2",  
    "moment": "^2.29.4",  
    "vue": ">= 2.6.14 < 2.7",  
    "vuex": "^3.2.0"  
  },  
  "devDependencies": {  
    "@dcloudio/types": "^3.3.2",  
    "@dcloudio/uni-automator": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-cli-i18n": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-cli-shared": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-helper-json": "*",  
    "@dcloudio/uni-migration": "^2.0.2-3090820231124001",  
    "@dcloudio/uni-template-compiler": "^2.0.2-3090820231124001",  
    "@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.2-3090820231124001",  
    "@dcloudio/vue-cli-plugin-uni": "^2.0.2-3090820231124001",  
    "@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.2-3090820231124001",  
    "@dcloudio/webpack-uni-mp-loader": "^2.0.2-3090820231124001",  
    "@dcloudio/webpack-uni-pages-loader": "^2.0.2-3090820231124001",  
    "@vue/cli-plugin-babel": "~5.0.0",  
    "@vue/cli-service": "~5.0.0",  
    "babel-plugin-import": "^1.11.0",  
    "cross-env": "^7.0.2",  
    "jest": "^25.4.0",  
    "postcss-comment": "^2.0.0",  
    "sass": "^1.26.5",  
    "sass-loader": "^8.0.2",  
    "vue-template-compiler": ">= 2.6.14 < 2.7"  
  },

package.json 脚本命令

新增自定义变量:VUE_APP_API_ENV

"build:app-plus-sit": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus VUE_APP_API_ENV=sit vue-cli-service uni-build"

操作步骤:

如上代码,新增多个打包环境命令自定义变量 VUE_APP_API_ENV=sit
在vue和nvue中打印process.env.VUE_APP_API_ENV

预期结果:

预期都能打印出”sit“

实际结果:

vue页面可以打印出”sit“
nvue页面打印出”undefined“

bug描述:

通过uni cli打包成wgt文件时,发现项目中nvue页面在获取打包自定义环境变量时为undefined,而在vue页面中可以正常获取得到

2023-12-28 14:29 负责人:无 分享
已邀请:
s***@outlook.com

s***@outlook.com (作者)

给@dcloudio/vue-cli-plugin-hbuilderx包打了个补丁解决了

要回复问题请先登录注册