-
Notifications
You must be signed in to change notification settings - Fork 0
feat(turbopack): support exposeEntryExports config #108
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
base: utoo
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @fireairforce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances Turbopack's browser build process by adding a new configuration option, Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
本次 PR 为 Turbopack 添加了一个新的配置项 exposeEntryExports。启用后,它会将入口模块的导出内容暴露到全局作用域(globalThis)。此功能主要是为了支持像 qiankun 这样的微前端框架,因为子应用需要导出其生命周期函数。
实现方式是在 BrowserChunkingContext 中添加了相应的配置选项,并在浏览器运行时中注入一小段 JavaScript 代码来处理导出逻辑。
整体代码结构清晰,实现方式合理。我有一个建议,旨在移除运行时代码中的一个硬编码前缀,以提高该功能的通用性。
| if (entryModule && entryModule.exports) {{ | ||
| const moduleExports = entryModule.namespaceObject || entryModule.exports; | ||
|
|
||
| const exportName = "{chunk_loading_global}".replace(/^utooChunk_/, "").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.
exportName 的派生逻辑中硬编码了 utooChunk_ 前缀。这使得该功能与某个特定项目的命名约定高度耦合,降低了其在 Turbopack 中的通用性。为了使该功能更通用,建议移除对 utooChunk_ 的替换。这样,用户可以通过 chunk_loading_global 选项来控制最终的导出名称。
| const exportName = "{chunk_loading_global}".replace(/^utooChunk_/, "").replace(/_/g, "-"); | |
| const exportName = "{chunk_loading_global}".replace(/_/g, "-"); |
7b5718d to
24f791a
Compare
支持
exposeEntryExports配置。为了解决 issue: utooland/utoo#2532qiankun 需要子应用在 entry chunk 暴露出对应的运行时函数: https://qiankun.umijs.org/zh/guide/tutorial#%E5%BE%AE%E5%BA%94%E7%94%A8
在 webpack 场景下,qiankun 子应用通常处理方式为把应用构造成 library 的形式(一般是 umd 格式):
webpack 的 library 产物格式支持入口函数的导出,参考文档: https://webpack.js.org/configuration/output/#outputlibrary
但目前 utoopack / turbopack 并不支持这种 library 形式的输出(utoopack 的 library umd 仅支持 bundle 出一个 single chunk)。
为了适配这里 qiankun 子应用的函数导出,这里有两个方案:
在 umi 下添加一个 qiankun-slave-utoopack 的 plugin,按照 qiankun 非 webpack bundle 的方式去构造一个 runtime chunk 通过
<script>提前加载进去(https://github.com/umijs/umi/blob/master/packages/plugins/src/qiankun/slave.ts#L197-L203),评估过后发现这里 umi / qiankun 逻辑耦合比较深,改不动utoopack 的 app 构建添加一个配置叫
exposeEntryExports来通过运行时构造把 entry chunk 里面的一些函数导出给从 entry chunk 里面导出出去: