1***@qq.com
1***@qq.com
  • 发布:2023-08-22 11:30
  • 更新:2023-08-22 11:30
  • 阅读:136

HbuilderX创建的项目配置动态修改manifest.json的值提示src\manifest.json 不存在

分类:HBuilderX

HbuilderX创建的项目配置动态修改manifest.json的值,运行后提示src\manifest.json 不存在,HbuilderX创建的项目并没有src目录啊为什么会提示src目录呢,配置是根据官网提示的创建vue.config.js,获取的路径我也把src去掉了

const fs = require('fs')

const manifestPath = './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')
}

2023-08-22 11:30 负责人:DCloud_UNI_GSQ 分享
已邀请:

要回复问题请先登录注册