Skip to content

Commit a021643

Browse files
authored
docs: add registerPlugins docs (#3060)
1 parent b704f30 commit a021643

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

apps/website-new/docs/en/guide/basic/runtime.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ loadRemote<{add: (...args: Array<number>)=> number }>("app2/util").then((md)=>{
5858
### init
5959

6060
- Type: `init(options: InitOptions): void`
61-
- Creates a runtime instance, which can be dynamically re-registered, but only one instance exists.
61+
- Create a runtime instance, which can be called repeatedly, but only one instance exists. If you want to dynamically register remotes or plugins, use [registerPlugins](#registerplugins) or [registerRemotes](#registerremotes)
6262
- InitOptions:
6363

6464
```typescript
@@ -406,6 +406,23 @@ registerRemotes([
406406
], { force: true });
407407
```
408408
409+
### registerPlugins
410+
411+
- Type: `registerPlugins(plugins: FederationRuntimePlugin[]): void`
412+
- Used to register plugins after initialization
413+
414+
- Example
415+
416+
```ts
417+
import { registerPlugins } from '@module-federation/enhanced/runtime'
418+
import runtimePlugin from 'custom-runtime-plugin.ts';
419+
420+
registerPlugins([runtimePlugin()]);
421+
```
422+
423+
If you want to develop Module Federation plugin, you can read [Module Federation Plugin System](../../plugin/dev/index) for more info.
424+
425+
409426
## FAQ
410427
411428
### Differences Between Build Plugins and Runtime

apps/website-new/docs/en/plugin/dev/index.mdx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ const path = require('path');
5858
module.exports = {
5959
plugins: [
6060
new ModuleFederation({
61-
name: 'host',
62-
remotes: {
63-
'manifest-provider':
64-
'manifest_provider@http://localhost:3011/mf-manifest.json',
65-
},
61+
// ...
6662
runtimePlugins: [path.resolve(__dirname, './custom-runtime-plugin.ts')],
6763
}),
6864
],
@@ -72,18 +68,10 @@ module.exports = {
7268
- Runtime registration of plugins
7369

7470
```typescript
71+
import { registerPlugins } from '@module-federation/enhanced/runtime'
7572
import runtimePlugin from 'custom-runtime-plugin.ts';
76-
init({
77-
name: '@demo/app-main',
78-
remotes: [
79-
{
80-
name: '@demo/app2',
81-
entry: 'http://localhost:3006/mf-manifest.json',
82-
alias: 'app2',
83-
},
84-
],
85-
plugins: [runtimePlugin()],
86-
});
73+
74+
registerPlugins([runtimePlugin()]);
8775
```
8876

8977
### Plugin Structure

apps/website-new/docs/zh/guide/basic/runtime.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ loadRemote<{add: (...args: Array<number>)=> number }>("app2/util").then((md)=>{
5858
### init
5959

6060
- Type: `init(options: InitOptions): void`
61-
- 创建运行时实例,它可以通过重新调用动态注册远程,但只存在一个实例。
61+
- 创建运行时实例,它可以重复调用,但只存在一个实例。若想动态注册远程模块或插件,请使用 [registerPlugins](#registerplugins)[registerRemotes](#registerremotes)
6262
- InitOptions:
6363

6464
```ts
@@ -406,6 +406,23 @@ registerRemotes([
406406
], { force: true });
407407
```
408408
409+
410+
### registerPlugins
411+
412+
- Type: `registerPlugins(plugins: FederationRuntimePlugin[]): void`
413+
- 用于在初始化后注册远程插件.
414+
415+
- Example
416+
417+
```ts
418+
import { registerPlugins } from '@module-federation/enhanced/runtime'
419+
import runtimePlugin from 'custom-runtime-plugin.ts';
420+
421+
registerPlugins([runtimePlugin()]);
422+
```
423+
424+
如果你需要开发 Module Federation 插件,可以阅读 [Module Federation 插件系统](../../plugin/dev/index) 获取更多信息。
425+
409426
## FAQ
410427
411428
### 构建插件和 Runtime 差异

apps/website-new/docs/zh/plugin/dev/index.mdx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ const path = require('path');
5858
module.exports = {
5959
plugins: [
6060
new ModuleFederation({
61-
name: 'host',
62-
remotes: {
63-
'manifest-provider':
64-
'manifest_provider@http://localhost:3011/mf-manifest.json',
65-
},
61+
// ...
6662
runtimePlugins: [path.resolve(__dirname, './custom-runtime-plugin.ts')],
6763
}),
6864
],
@@ -72,18 +68,10 @@ module.exports = {
7268
- 运行时注册插件
7369

7470
```ts
71+
import { registerPlugins } from '@module-federation/enhanced/runtime'
7572
import runtimePlugin from 'custom-runtime-plugin.ts';
76-
init({
77-
name: '@demo/app-main',
78-
remotes: [
79-
{
80-
name: '@demo/app2',
81-
entry: 'http://localhost:3006/mf-manifest.json',
82-
alias: 'app2',
83-
},
84-
],
85-
plugins: [runtimePlugin()],
86-
});
73+
74+
registerPlugins([runtimePlugin()]);
8775
```
8876

8977
### 插件结构
@@ -677,4 +665,4 @@ import test1 from "delegateModulesA/test1"
677665
import test2 from "delegateModulesA/test2"
678666
test1 // "test1 value"
679667
test2 // "test2 value"
680-
```
668+
```

0 commit comments

Comments
 (0)