-
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
feat(preset-umi): support to preload route chunk files #12095
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Size Change: +4.16 kB (0%) Total Size: 9.9 MB
ℹ️ View Unchanged
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #12095 +/- ##
==========================================
- Coverage 28.76% 28.48% -0.29%
==========================================
Files 489 492 +3
Lines 14968 15119 +151
Branches 3560 3601 +41
==========================================
+ Hits 4305 4306 +1
- Misses 9897 10041 +144
- Partials 766 772 +6 ☔ View full report in Codecov by Sentry. |
7fc7f43
to
f9c509a
Compare
if (routePath) { | ||
const map = '{{routeChunkFilesMap}}' as any; | ||
const doc = document; | ||
const head = doc.head; |
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.
新增异常处理:head 可能不存在。
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.
head 应该是始终存在的,因为脚本插入时机是 addHTMLHeadScripts
packages/preset-umi/src/features/firstRoutePreload/firstRoutePreload.ts
Outdated
Show resolved
Hide resolved
@@ -2,11 +2,19 @@ import { checkVersion } from '@umijs/utils'; | |||
import { IApi } from '../../types'; | |||
|
|||
export default (api: IApi) => { | |||
api.describe({ | |||
enableBy: () => Boolean(process.env.OKAM), |
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.
process.env.OKAM
有整合的思路吗,现在代码里好几处飞线的 process.env.OKAM
散落在各处。
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.
整合的话似乎只能挂 service 上,消费的地方都能拿到 api
packages/preset-umi/src/features/routePreloadOnLoad/routePreloadOnLoad.ts
Outdated
Show resolved
Hide resolved
packages/preset-umi/src/features/routePreloadOnLoad/routePreloadOnLoad.ts
Outdated
Show resolved
Hide resolved
由于 |
可以增加个开关吗? |
可能是脚本插入到 qiankun 改 publicPath 的脚本后面了,ref: umi/packages/plugins/src/qiankun/slave.ts Line 177 in 56313d4
有空的话帮忙验证下上面的猜想,如果确认欢迎提个 PR 调整下 preload 插件插入 headScripts 的钩子 stage 优先级,可以挪到最后面 |
我本地开启nginx 测试了下,换了个位置后,错误信息没有提示出来了 |
我部署的代码验证还是有问题。主应用base为 /base-web,publicPath为:/static-base-web/ 子应用base为 /child-web,publicPath为:/static-child-web/ 升级到最新版umi后发现预加载子应用的js和css 都是不带/static-child-web/的 导致控制台看起来一大片404。于是回退umi到4.1.5版本 发现功能正常 不会有预加载的404 求问如何解决 |
支持根据访问路由预加载子路由 chunk 文件,主要改动点:
api.appData.bundler
的逻辑,用于标记预加载脚本script
模式为默认值会在 HTML 产物中插入 inline script,该 script 会根据访问路由自动添加 async script 标签和 preload link 标签预加载访问该子路由需要的所有资源(不含子路由渲染逻辑内的异步加载资源);而map
模式则会输出路由资源映射表,配合 Umi 提供的方法可以在微前端等场景实现自定义的资源预加载(仅用于内部场景)补下原理示意图:
