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: support modifyHTMLOnComplete #11166
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: +708 B (0%) Total Size: 9.85 MB
ℹ️ View Unchanged
|
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #11166 +/- ##
==========================================
- Coverage 29.14% 29.11% -0.04%
==========================================
Files 479 479
Lines 14424 14440 +16
Branches 3395 3400 +5
==========================================
Hits 4204 4204
- Misses 9492 9505 +13
- Partials 728 731 +3
☔ View full report in Codecov by Sentry. |
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.
额,看了下,发现这是 runtime 插件,你确定需要的是 runtime 插件?
1、不在 tmpFiles.ts 里加入 validKeys 应该是跑不通的,你这是盲改没跑过示例的吗?
2、runtime modify 类型的可以搜下,得加 type 和 initialValue,比如这个
const runtimeDva = pluginManager.applyPlugins({
key: 'dva',
type: ApplyPluginsType.modify,
initialValue: {},
});
3、runtime 插件不需要 registerMethod 和 types.ts 声明,还有文档也写错地方了
我看看,应该不是 runtime 吧,生成 html 是浏览器里做的吗? |
我重新考虑下这个api怎么搞,参考下 nextjs |
nextjs 的思路我们不好参考,我加了个 modifyHTMLOnComplete 来专门处理最后一步的 html,在 ssr 场景中,这个api会多次调用,也正好根据每次不同页面来生成不同的 css 文件 |
/** | ||
* 编译完成后,修改 html | ||
* 在 modifyHTML 和 modifyHTMLFavicon之后执行 | ||
* modifyHTML 里面做了太多操作,为了防止顺序问题,所以新增一个钩子 |
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.
用 Infinity
的 stage 不行吗,一定是处理完的最后位置。
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.
两个 Infinity 的优先级怎么控制呢?
我有点担心变成了 zindex,你高 我比你更高,我比你更高高
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.
如果两个都是自己可控的话,可以通过 Infinity - 1
/ Infinity - n
来控制顺序,如果不是自己控制的,是按照插件注册顺序来的,通过改变插件注册顺序即可。
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.
用 Infinity 的 stage 不行吗,一定是处理完的最后位置。
+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.
怎么改变插件的注册顺序 ?我看好几个插件用了
都用了 modifyHTML ,都是约定注册的,这种要怎么控制
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.
注册顺序就是在 plugins: []
里写的顺序,比如一个 preset 他有很多 plugins ,是一个列表,是有先后顺序的;另外用户自己的 plugins
配置项是最后加载的。
比如这样的顺序:
plugins: [
require.resolve('./features/404/404'),
require.resolve('./features/appData/appData'),
require.resolve('./features/appData/umiInfo'),
require.resolve('./features/check/check'),
]
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.
这是在自己能控制插件的时候 如果是多个 preset 呢
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.
多个 preset 可以控制 preset 加载顺序,你尝试下。
modifyHTMLOnComplete
编译完 html 发生, 在返回 html 的最后一步。与 modifyHTML 相比,modifyHTMLOnComplete 发生事件更加靠后,在各类插件处理完 html 之后才会返回。