uniapp 拆包

举报
皮耶罗夫斯基 发表于 2024/11/29 15:56:57 2024/11/29
【摘要】 安装 uni-pages-hot-modules 插件npm i uni-pages-hot-modules -S在项目根目录新建 src\pages.js/* * @Description: * @Author: lu jia ming * @Date: 2024-08-14 10:11:13 * @LastEditors: lu jia ming * @LastEditTime: 20...

安装 uni-pages-hot-modules 插件

npm i uni-pages-hot-modules -S

在项目根目录新建 src\pages.js

/*
 * @Description: 
 * @Author: lu jia ming
 * @Date: 2024-08-14 10:11:13
 * @LastEditors: lu jia ming
 * @LastEditTime: 2024-08-14 14:21:47
 */

/*
 *uni-app自带一个webpack loader钩子文件pages.js,在项目根目录下建立pages.js(与pages.json同级)即可生效
 * pages.js要求CommonJS规范,直接通过module.exports输出一个钩子函数。
*/

const { hot } = require('uni-pages-hot-modules')
module.exports = hot((pagesJson) => {
    return {
        ...pagesJson,
        pages:[
            ...require('./router/buildRouter.js').pages,
        ]
    }
})


在项目根目录新建 src\router\buildRouter.js

/*
 * @Description: 
 * @Author: lu jia ming
 * @Date: 2024-08-14 10:11:43
 * @LastEditors: lu jia ming
 * @LastEditTime: 2024-08-14 14:22:40
 */
/*此文件用来动态加载pages下的页面路径
 */
let pagesJson = {
  "pages": [
    {
      "path": "pages/index/watch",
      "style": {
        "navigationStyle": "custom"
      }
    },
    {
      "path": "pages/index/manage",
      "style": {
        "navigationStyle": "custom"
      }
    },
    {
      "path": "pages/index/more",
      "style": {
        "navigationStyle": "custom"
      }
    }
  ]
}
// /pages/目录下的模块名称
const mainPages = ['warehouse', 'production', 'ERPManage','basic']
mainPages.forEach(async (item) => {
  const moduleRouter = require(`../pages/${item}/PagesConfig.js`)
  
  moduleRouter.forEach((subItem) => {
    pagesJson.pages.push(subItem)
  })
})

module.exports = pagesJson

比如拆分 warehouse 以及 production

在项目文件夹下新建 src\pages\warehouse\PagesConfig.js

/*
 * @Description: 
 * @Author: lu jia ming
 * @Date: 2024-08-14 10:05:05
 * @LastEditors: lu jia ming
 * @LastEditTime: 2024-08-14 11:01:43
 */
module.exports = [
    {
      "path": "pages/warehouse/require/index",
      "style": {
        "navigationStyle": "custom",
        "enablePullDownRefresh": true
      }
    },
    {
      "path": "pages/warehouse/inStore/index",
      "style": {
        "navigationStyle": "custom",
        "enablePullDownRefresh": true
      }
    },
    {
      "path": "pages/warehouse/outStore/index",
      "style": {
        "navigationStyle": "custom",
        "enablePullDownRefresh": true
      }
    },
    {
      "path": "pages/warehouse/check/index",
      "style": {
        "navigationStyle": "custom",
        "enablePullDownRefresh": true
      }
    },
    {
      "path": "pages/warehouse/transfer/index",
      "style": {
        "navigationStyle": "custom",
        "enablePullDownRefresh": true
      }
    }
]

此时pages.json文件内容如下,将pages数组移除即可

{
  "easycom": {
    "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
  },
  "globalStyle": {
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "新农人小能手",
    "navigationBarBackgroundColor": "#F8F8F8",
    "backgroundColor": "#F8F8F8"
  },
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/watch"
      },
      {
        "pagePath": "pages/index/message"
      },
      {
        "pagePath": "pages/index/manage"
      },
      {
        "pagePath": "pages/index/system-oa/oa-manage"
      },
      {
        "pagePath": "pages/index/system-oa/workspace"
      },
      {
        "pagePath": "pages/index/system-oa/message"
      },
      {
        "pagePath": "pages/base-mine/oa-index"
      }
    ]
  }
}


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。