dumi icon indicating copy to clipboard operation
dumi copied to clipboard

Separate meta from routes

Open xiaohuoni opened this issue 4 years ago • 5 comments

🤔 这个变动的性质是?/ What is the nature of this change?

  • [ ] 新特性提交 / New feature
  • [ ] bug 修复 / Fix bug
  • [ ] 样式优化 / Style optimization
  • [ ] 代码风格优化 / Code style optimization
  • [x] 性能优化 / Performance optimization
  • [ ] 构建优化 / Build optimization
  • [ ] 网站、文档、Demo 改进 / Website, documentation, demo improvements
  • [ ] 重构代码或样式 / Refactor code or style
  • [ ] 测试相关 / Test related
  • [ ] 其他 / Other

🔗 相关 Issue / Related Issue

💡 需求背景和解决方案 / Background or solution

dumi 构建需要的 meta 信息,保存在 routes 中,导致 routes 对象巨大,特别是当开启 ssr 时,routes 会有两个一摸一样的数据,分别存于前端和服务端 js 中,导致整体项目大小增加不少。

现将 meta 数据,从 routes 中抽离出来放到 .umi/dumi/metas.json 中。

组件级别可以通过 import metas from '@@/dumi/metas'; 读取。

umi 插件中可以通过 const metas = await api!.getMetas(); 读取。

dumi 主题中,依旧使用 useCurrentRouteMeta 读取。

📝 更新日志 / Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese

xiaohuoni avatar Feb 25 '21 09:02 xiaohuoni

🎊 PR Preview 6cc42b4bf8725a9c944c69adf49bd122be5bd073 has been successfully built and deployed to https://umijs-dumi-preview-pr-568.surge.sh

:clock1: Build time: 217.737s

🤖 By surge-preview

github-actions[bot] avatar Feb 25 '21 09:02 github-actions[bot]

🎊 PR Preview 6cc42b4bf8725a9c944c69adf49bd122be5bd073 has been successfully built and deployed to https://umijs-dumi-preview-mobile-pr-568.surge.sh

:clock1: Build time: 177.513s

🤖 By surge-preview

github-actions[bot] avatar Feb 25 '21 09:02 github-actions[bot]

提个思路看看是不是更好:

  1. features/routes.ts 做两件事: a. 通过 api.modifyRoutes(umi 最后一个处理路由的钩子),基于原 routes 返回一个新的、不带 meta 的 routes,同时把带 meta 的原始 routes 存下来 b. 注册 dumi.getMetaRoutes key(类似 dumi.getRootRoute),用于获取带 meta 的 routes
  2. features/config.ts 里通过 dumi.getMetaRoutes 拿路由,再用来生成导航、菜单等等

好处是大部分原有逻辑都不用改,特殊路径少好写用例

PeachScript avatar Feb 25 '21 11:02 PeachScript

🎊 PR Preview has been successfully built and deployed to https://dumi-preview-pr-568.surge.sh

github-actions[bot] avatar Mar 01 '21 02:03 github-actions[bot]

🎊 PR Mobile Preview has been successfully built and deployed to https://dumi-mobile-preview-pr-568.surge.sh

github-actions[bot] avatar Mar 01 '21 02:03 github-actions[bot]

❤️ 感谢贡献,dumi v1 不再更新,PR 将会关闭;dumi v2 已发布,欢迎继续参与 dumi 的建设,https://d.umijs.org/

PeachScript avatar Jan 28 '23 09:01 PeachScript