Skip to content

Conversation

@fireairforce
Copy link

支持 exposeEntryExports 配置。为了解决 issue: utooland/utoo#2532

qiankun 需要子应用在 entry chunk 暴露出对应的运行时函数: https://qiankun.umijs.org/zh/guide/tutorial#%E5%BE%AE%E5%BA%94%E7%94%A8

在 webpack 场景下,qiankun 子应用通常处理方式为把应用构造成 library 的形式(一般是 umd 格式):

image

webpack 的 library 产物格式支持入口函数的导出,参考文档: https://webpack.js.org/configuration/output/#outputlibrary

但目前 utoopack / turbopack 并不支持这种 library 形式的输出(utoopack 的 library umd 仅支持 bundle 出一个 single chunk)。

为了适配这里 qiankun 子应用的函数导出,这里有两个方案:

image

@gemini-code-assist
Copy link

Summary of Changes

Hello @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, exposeEntryExports. This feature allows the exports of an application's entry module to be made available in the global scope. This is crucial for integrating with micro-frontend architectures, such as those using qiankun, which depend on accessing specific runtime functions from the main application entry point. The change provides a direct solution to a common interoperability challenge, simplifying the development and deployment of micro-frontend applications with Turbopack.

Highlights

  • New Configuration Option: Introduced a new exposeEntryExports boolean configuration option within Turbopack's browser chunking context.
  • Global Export Capability: This new option enables the automatic exposure of entry module exports to the global scope (window/globalThis) when activated.
  • Micro-frontend Compatibility: The feature specifically addresses compatibility requirements for micro-frontend frameworks like qiankun, which need entry points to expose runtime functions for proper operation.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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, "-");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

exportName 的派生逻辑中硬编码了 utooChunk_ 前缀。这使得该功能与某个特定项目的命名约定高度耦合,降低了其在 Turbopack 中的通用性。为了使该功能更通用,建议移除对 utooChunk_ 的替换。这样,用户可以通过 chunk_loading_global 选项来控制最终的导出名称。

Suggested change
const exportName = "{chunk_loading_global}".replace(/^utooChunk_/, "").replace(/_/g, "-");
const exportName = "{chunk_loading_global}".replace(/_/g, "-");

@fireairforce fireairforce force-pushed the support-runtime-code-expose branch from 7b5718d to 24f791a Compare January 28, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants