From 8b97411dbb89e91dceb6de20ced82b3a14db5f4b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 08:18:10 +0000 Subject: [PATCH 1/4] Initial plan From 65827fe3ca11b906c4eabb771ee3eea497f4f2b1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 08:22:01 +0000 Subject: [PATCH 2/4] docs: document global entry behavior in EntryPlugin Add documentation for global entry behavior (when name is undefined): - Global entries are now injected into both regular and async entrypoints - Includes use cases for webpack-dev-server and ModuleFederationPlugin - Added examples showing how global entries work with Workers Related to PR #12096 Co-authored-by: chenjiahan <7237365+chenjiahan@users.noreply.github.com> --- .../docs/en/plugins/webpack/entry-plugin.mdx | 32 +++++++++++++++++++ .../docs/zh/plugins/webpack/entry-plugin.mdx | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/website/docs/en/plugins/webpack/entry-plugin.mdx b/website/docs/en/plugins/webpack/entry-plugin.mdx index d43a3697ba5c..94a2dfd11238 100644 --- a/website/docs/en/plugins/webpack/entry-plugin.mdx +++ b/website/docs/en/plugins/webpack/entry-plugin.mdx @@ -40,3 +40,35 @@ type EntryOptions = If `options` is a string, its value will be used as `name`. Please refer to [Entry Description Object](/config/entry#entry-description-object) for all available options. + +## Global Entry + +When `options.name` is `undefined`, the entry is treated as a **global entry**. Global entries are special entries whose dependencies and included dependencies are injected into: + +1. **Regular entrypoints** - Normal entry chunks +2. **Async entrypoints** - Entry chunks created by `new Worker()` or other async entry mechanisms + +This behavior ensures that global dependencies (such as those added by webpack-dev-server for hot module replacement, or by ModuleFederationPlugin for runtime initialization) are available in all contexts, including Web Workers. + +### Use Cases + +Global entries are typically used by: + +- **webpack-dev-server**: Injects HMR (Hot Module Replacement) runtime code +- **ModuleFederationPlugin**: Injects Module Federation runtime initialization code +- **Custom plugins**: Can inject code that needs to be available across all entry contexts + +### Example + +```js +// Creating a global entry (name is undefined) +new rspack.EntryPlugin( + context, + './global-runtime.js', + { name: undefined } +); + +// This global entry will be included in both: +// - Regular entry chunks +// - Worker entry chunks created with new Worker() +``` diff --git a/website/docs/zh/plugins/webpack/entry-plugin.mdx b/website/docs/zh/plugins/webpack/entry-plugin.mdx index 180b480019f1..a563a976a2ce 100644 --- a/website/docs/zh/plugins/webpack/entry-plugin.mdx +++ b/website/docs/zh/plugins/webpack/entry-plugin.mdx @@ -40,3 +40,35 @@ type EntryOptions = 当 `options` 为字符串时,它的值会被作为 `name` 使用。 请参考 [入口描述对象](/config/entry#入口描述对象) 了解所有可用的选项。 + +## 全局入口 + +当 `options.name` 为 `undefined` 时,该入口会被视为**全局入口**。全局入口是特殊的入口,其依赖项和包含的依赖项会被注入到: + +1. **常规入口点** - 普通入口 chunk +2. **异步入口点** - 由 `new Worker()` 或其他异步入口机制创建的入口 chunk + +此行为确保全局依赖项(例如 webpack-dev-server 添加的热模块替换相关代码,或 ModuleFederationPlugin 添加的运行时初始化代码)在所有上下文中都可用,包括 Web Workers。 + +### 使用场景 + +全局入口通常由以下场景使用: + +- **webpack-dev-server**:注入 HMR(热模块替换)运行时代码 +- **ModuleFederationPlugin**:注入模块联邦运行时初始化代码 +- **自定义插件**:可以注入需要在所有入口上下文中可用的代码 + +### 示例 + +```js +// 创建一个全局入口(name 为 undefined) +new rspack.EntryPlugin( + context, + './global-runtime.js', + { name: undefined } +); + +// 此全局入口将被包含在: +// - 常规入口 chunk +// - 使用 new Worker() 创建的 worker 入口 chunk +``` From 3e188b02f296541ed60d4d0bfe457d1f8f49d3d5 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 9 Nov 2025 16:03:59 +0800 Subject: [PATCH 3/4] Update entry-plugin.mdx --- .../docs/zh/plugins/webpack/entry-plugin.mdx | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/website/docs/zh/plugins/webpack/entry-plugin.mdx b/website/docs/zh/plugins/webpack/entry-plugin.mdx index a563a976a2ce..6dbfcfc99602 100644 --- a/website/docs/zh/plugins/webpack/entry-plugin.mdx +++ b/website/docs/zh/plugins/webpack/entry-plugin.mdx @@ -43,32 +43,17 @@ type EntryOptions = ## 全局入口 -当 `options.name` 为 `undefined` 时,该入口会被视为**全局入口**。全局入口是特殊的入口,其依赖项和包含的依赖项会被注入到: +当插件的 `name` 选项为 `undefined` 时,该入口被视为全局入口,它会自动注入到: -1. **常规入口点** - 普通入口 chunk -2. **异步入口点** - 由 `new Worker()` 或其他异步入口机制创建的入口 chunk +1. 所有常规入口 chunk +2. 所有异步入口(例如通过 `new Worker()` 创建的 worker chunk) -此行为确保全局依赖项(例如 webpack-dev-server 添加的热模块替换相关代码,或 ModuleFederationPlugin 添加的运行时初始化代码)在所有上下文中都可用,包括 Web Workers。 - -### 使用场景 - -全局入口通常由以下场景使用: - -- **webpack-dev-server**:注入 HMR(热模块替换)运行时代码 -- **ModuleFederationPlugin**:注入模块联邦运行时初始化代码 -- **自定义插件**:可以注入需要在所有入口上下文中可用的代码 - -### 示例 +这可以用于注入一段全局代码,例如 dev server 的热更新运行时代码,或是模块联邦的初始化逻辑。 ```js -// 创建一个全局入口(name 为 undefined) new rspack.EntryPlugin( context, './global-runtime.js', { name: undefined } ); - -// 此全局入口将被包含在: -// - 常规入口 chunk -// - 使用 new Worker() 创建的 worker 入口 chunk ``` From 224a36f30ddcf077648652a926c7172c0aead732 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 9 Nov 2025 16:05:25 +0800 Subject: [PATCH 4/4] Update entry-plugin.mdx --- .../docs/en/plugins/webpack/entry-plugin.mdx | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/website/docs/en/plugins/webpack/entry-plugin.mdx b/website/docs/en/plugins/webpack/entry-plugin.mdx index 94a2dfd11238..851f60a0eca2 100644 --- a/website/docs/en/plugins/webpack/entry-plugin.mdx +++ b/website/docs/en/plugins/webpack/entry-plugin.mdx @@ -39,36 +39,21 @@ type EntryOptions = If `options` is a string, its value will be used as `name`. -Please refer to [Entry Description Object](/config/entry#entry-description-object) for all available options. +Refer to [Entry description object](/config/entry#entry-description-object) for all available options. -## Global Entry +## Global entry -When `options.name` is `undefined`, the entry is treated as a **global entry**. Global entries are special entries whose dependencies and included dependencies are injected into: +When the plugin's `name` option is set to `undefined`, the entry is treated as a global entry. It's automatically injected into: -1. **Regular entrypoints** - Normal entry chunks -2. **Async entrypoints** - Entry chunks created by `new Worker()` or other async entry mechanisms +1. All regular entry chunks +2. All asynchronous entries (for example, worker chunks created with `new Worker()`) -This behavior ensures that global dependencies (such as those added by webpack-dev-server for hot module replacement, or by ModuleFederationPlugin for runtime initialization) are available in all contexts, including Web Workers. - -### Use Cases - -Global entries are typically used by: - -- **webpack-dev-server**: Injects HMR (Hot Module Replacement) runtime code -- **ModuleFederationPlugin**: Injects Module Federation runtime initialization code -- **Custom plugins**: Can inject code that needs to be available across all entry contexts - -### Example +This allows you to inject global runtime code, such as the dev server's HMR runtime or the initialization logic for module federation. ```js -// Creating a global entry (name is undefined) new rspack.EntryPlugin( context, './global-runtime.js', { name: undefined } ); - -// This global entry will be included in both: -// - Regular entry chunks -// - Worker entry chunks created with new Worker() ```