/*
分包转换
*/
function pagesTransSubPackages(pages){
let SubPackages = [];
let node = {"root":"","pages":[]};
let page = {"path":"","style":{}};
let dict = new Map();let pos = 0;
for(let single of pages){
let paths = single.path.split('/')
node.root = paths.slice(0,2).join('/');
if(dict.has(node.root)){
page.path = paths.slice(2).join('/');
page.style = single.style;
SubPackages[dict.get(node.root)].pages.push(page);
}else{
dict.set(node.root,pos);
page.path = paths.slice(2).join('/');
page.style = single.style
node.pages.push(page)
SubPackages.push(node);
pos++
}
// reset data
node = {"root":"","pages":[]};
page = {"path":"","style":{}};
}
return SubPackages;
}
/**
* 1、去pages.json挑选出全部pages数组替换到pages变量
* 2、node pagesTransSubPackages.js文件输出的json在https://uutool.cn/nl-trim-all/网站上去掉所有换行
* 3、替换到原来pages.json的SubPackages的数组
* 4、将首屏需要加载的包从pages.json的SubPackages的数组中删掉
* 5、愉快的运行微信小程序
*/
let pages = [{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页",
"navigationStyle": "custom",
"app-plus" : {
// "statusbar": {
// "immersed": false
// }
}
}
},
{
"path": "pages/classify/classify",
"style": {
"navigationBarTitleText": "分类",
"navigationStyle": "custom"
}
},
{
"path": "pages/straight/straight",
"style": {
"navigationBarTitleText": "找医护",
"navigationStyle": "custom",
"app-plus" : {
// "statusbar": {
// "immersed": false
// }
}
}
},
{
"path": "pages/webUrl/index",
"style": {
"navigationBarTitleText": "外部链接",
"navigationStyle": "custom"
}
}]
console.info(JSON.stringify(pagesTransSubPackages(pages)));
1、去pages.json挑选出全部pages数组替换到pages变量
2、node pagesTransSubPackages.js文件输出的json在https://uutool.cn/nl-trim-all/网站上去掉所有换行
3、替换到原来pages.json的SubPackages的数组
4、将首屏需要加载的包从pages.json的SubPackages的数组中删掉
5、愉快的运行微信小程序