tsung
tsung
  • 发布:2023-02-09 15:48
  • 更新:2023-02-09 15:48
  • 阅读:211

为什么在打包发布小程序的时候,appid需要必填?

分类:HBuilderX

为什么再打包发布的时候小程序appid为必填?
采用官方动态的配置小程序appid并不能生效

发布时动态修改 manifest.json

// 读取 manifest.json ,修改后重新写入  
const fs = require('fs');  
  
const manifestPath = './src/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');  
}  
// 使用  
replaceManifest('app-plus.usingComponents', false);  
replaceManifest('app-plus.splashscreen.alwaysShowBeforeRender', false);  
replaceManifest('mp-baidu.usingComponents', false);  
fs.writeFileSync(manifestPath, Manifest, {  
	flag: 'w',  
});  
  
export default defineConfig({  
	// ...  
});
2023-02-09 15:48 负责人:无 分享
已邀请:

要回复问题请先登录注册