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')
}
0 个回复