w***@163.com
w***@163.com
  • 发布:2025-03-29 09:15
  • 更新:2025-03-29 10:01
  • 阅读:32

【报Bug】HubilderX在4.56及新版在微信小程序发版使用CLI不可用

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: windows10

HBuilderX类型: 正式

HBuilderX版本号: 4.56

第三方开发者工具版本号: 1.06.2412050

基础库版本号: 3.7.12

项目创建方式: HBuilderX

示例代码:

// 导入fs模块
const fs = require('fs')
// 导入环境变量配置文件
const ENV_CONFIG = require('./config/env.js');
const manifestPath = ${__dirname}/manifest.json;
let Manifest = fs.readFileSync(manifestPath, {
encoding: 'utf-8'
})

function replaceManifest(path, value) {
const arr = path.split('.')
const len = arr.length
const lastItem = arr[len - 1]

let i = 0  
let ManifestArr = Manifest.split(/\n/)  

for (let index = 0; index < ManifestArr.length; index++) {  
    const item = ManifestArr[index]  
    if (new RegExp(`"${arr[i]}"`).test(item)) ++i  
    if (i === len) {  
        const hasComma = /,/.test(item)  
        ManifestArr[index] = item.replace(  
            new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`),  
            `"${lastItem}": ${value}${hasComma ? ',' : ''}`  
        )  
        break  
    }  
}  
Manifest = ManifestArr.join('\n')  

}

if(process.env.NODE_ENV=='development'){
process.env.UNI_APP_NAME=process.env.UNI_SCRIPT
}

//测试发布功能
// console.log(ENV_CONFIG)
// console.log("-----------------------")
// console.log(process.env)
// console.log("-----------------------")
// console.log(process.env)
// console.log("-----------------------")
// console.log(ENV_CONFIG.profiles)
console.log(process.env)

console.log(process.env.UNI_APP_NAME)
console.log("-----------------------")
// const appid = ENV_CONFIG[process.env.UNI_APP_NAME].appid
//测试测试
// process.env.UNI_APP_NAME='baosimai'
//process.env.UNI_APP_NAM

const appid = ENV_CONFIG[ENV_CONFIG.profiles.active].appid
console.log(appid)
if (appid) {
// #ifdef MP-WEIXIN
replaceManifest('mp-weixin.appid', "${appid}")
// #endif
// #ifdef MP-ALIPAY
replaceManifest('mp-alipay.appid', "${appid}")
// #endif
}

fs.writeFileSync(manifestPath, Manifest, {
flag: 'w'
})

操作步骤:

对于CLI发行时候在老版本的Hbuilder中是可以使用cli -name 然后在vue.config.js中使用process.env.UNI_APP_NAME获取到命令执行时的-name 但是升级到4.56以及4.57后均获取不到

预期结果:


console.log(process.env.UNI_APP_NAME)这块打印时候出现的是我cli执行时候-name xxx中的xxx而不mainifest.json中的name

实际结果:

目前cli执行在新版本的hbuilderx中不生效

bug描述:

对于CLI发行时候在老版本的Hbuilder中是可以使用cli -name 然后在vue.config.js中使用process.env.UNI_APP_NAME获取到命令执行时的-name 但是升级到4.56以及4.57后均获取不到
但是我有4.56之前的hbuilder都是直接执行命令时直接获取到-name的 而不是配置文件中写死的

2025-03-29 09:15 负责人:无 分享
已邀请:
w***@163.com

w***@163.com (作者) - 111

这是我使用HbuilderX3.9.9 随便在cli -name 1111 在打印中是可以获取到1111的

要回复问题请先登录注册