Skip to content

Commit 5cba000

Browse files
Copilotchenjiahan
andauthored
docs: document global entry behavior in EntryPlugin (#12105)
* Initial plan * 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> * Update entry-plugin.mdx * Update entry-plugin.mdx --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chenjiahan <7237365+chenjiahan@users.noreply.github.com> Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
1 parent 939d9a8 commit 5cba000

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

website/docs/en/plugins/webpack/entry-plugin.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,21 @@ type EntryOptions =
3939

4040
If `options` is a string, its value will be used as `name`.
4141

42-
Please refer to [Entry Description Object](/config/entry#entry-description-object) for all available options.
42+
Refer to [Entry description object](/config/entry#entry-description-object) for all available options.
43+
44+
## Global entry
45+
46+
When the plugin's `name` option is set to `undefined`, the entry is treated as a global entry. It's automatically injected into:
47+
48+
1. All regular entry chunks
49+
2. All asynchronous entries (for example, worker chunks created with `new Worker()`)
50+
51+
This allows you to inject global runtime code, such as the dev server's HMR runtime or the initialization logic for module federation.
52+
53+
```js
54+
new rspack.EntryPlugin(
55+
context,
56+
'./global-runtime.js',
57+
{ name: undefined }
58+
);
59+
```

website/docs/zh/plugins/webpack/entry-plugin.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ type EntryOptions =
4040
`options` 为字符串时,它的值会被作为 `name` 使用。
4141

4242
请参考 [入口描述对象](/config/entry#入口描述对象) 了解所有可用的选项。
43+
44+
## 全局入口
45+
46+
当插件的 `name` 选项为 `undefined` 时,该入口被视为全局入口,它会自动注入到:
47+
48+
1. 所有常规入口 chunk
49+
2. 所有异步入口(例如通过 `new Worker()` 创建的 worker chunk)
50+
51+
这可以用于注入一段全局代码,例如 dev server 的热更新运行时代码,或是模块联邦的初始化逻辑。
52+
53+
```js
54+
new rspack.EntryPlugin(
55+
context,
56+
'./global-runtime.js',
57+
{ name: undefined }
58+
);
59+
```

0 commit comments

Comments
 (0)