-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(preset-umi): make 3rd-party chunk name clean #11716
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Size Change: +29 B (0%) Total Size: 10.2 MB
ℹ️ View Unchanged
|
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #11716 +/- ##
=======================================
Coverage 28.93% 28.93%
=======================================
Files 485 485
Lines 14771 14771
Branches 3498 3498
=======================================
Hits 4274 4274
Misses 9737 9737
Partials 760 760
☔ View full report in Codecov by Sentry. |
@@ -315,9 +315,15 @@ export function componentToChunkName( | |||
), | |||
'', | |||
) | |||
// 丢弃 .pnpm 下的多层 node_modules 避免 chunkName 过长 | |||
// ex. node_modules/.pnpm/[email protected]_xxxx/node_modules/dumi/dist/client/pages/404 | |||
.replace(/.+(node_modules(\/|\\))/, '$1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里把全局的 /node_modules(\/|\\)/g
干掉替换为空字符串就好了吧。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下面的 nm__ 前缀还是有必要的,极端情况下三方包内有可能和源码有一样的文件名
.replace(/.+(node_modules(\/|\\))/, '$1') | ||
// 丢弃 tnpm 目录下的软链结构避免 chunkName 过长 | ||
// ex. node_modules/_@[email protected]@@umijs/utils/dist/index.js | ||
.replace(/(\/|\\)_@?([^@]+@){2}/, '$1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我感觉只要干掉 _@xxxx/
这部分,_@
开头到下一个斜线就好了:
replace( /_@(.+?)(\/|\\)/g, '')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样 org 会丢?
对路由表中引用 node_modules 下的路由组件 chunk name 做优化,主要处理 pnpm 和 tnpm 的文件结构,对比效果:
问题背景:之前 dumi 为了解 chunk name 引起的 CDN 资源托管问题(包括但不限于 umijs/dumi#1487 ),用 alias 实现了 chunk name 的优化(见 umijs/dumi#1601 ),但这个实现的前提是 layouts 不会被 server loader 处理,因为 server loader 解析 route component 时不会处理 alias,在 #11666 后 layouts 也会被 server loader 处理,导致 4.0.84 发布后 dumi 应用报错
解决方案:把 chunk name 的简化交给 Umi 来处理 + dumi 回滚之前的方案
为什么不让 server loader 对路由组件的解析支持 alias:加上 alias 的处理也会比较麻烦,需要使用 enhanced-resolve,需要把 getRoutes 变成 async,问题会被扩大