HubilderX在4.56及新版在微信小程序发版使用CLI不可用 uni-app

HubilderX在4.56及新版在微信小程序发版使用CLI不可用 uni-app

开发环境 版本号 项目创建方式
Windows 10 HBuilderX

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

示例代码:

// 导入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'
})

更多关于HubilderX在4.56及新版在微信小程序发版使用CLI不可用 uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于HubilderX在4.56及新版在微信小程序发版使用CLI不可用 uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html


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

回到顶部