@modern-js/main-doc 2.65.5 → 2.66.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/apis/app/hooks/src/app.mdx +20 -34
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/en/apis/app/runtime/app/define-config.mdx +6 -0
- package/docs/en/community/blog/v2-release-note.mdx +1 -1
- package/docs/en/components/enable-micro-frontend.mdx +20 -3
- package/docs/en/components/micro-runtime-config.mdx +12 -13
- package/docs/en/components/reduck-notify.mdx +27 -0
- package/docs/en/configure/app/plugins.mdx +2 -2
- package/docs/en/configure/app/runtime/0-intro.mdx +63 -91
- package/docs/en/configure/app/tools/esbuild.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -1
- package/docs/en/configure/app/usage.mdx +93 -69
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +115 -0
- package/docs/en/guides/basic-features/routes.mdx +0 -95
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -4
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -5
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -4
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -5
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -5
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -5
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -4
- package/docs/en/guides/topic-detail/model/quick-start.mdx +5 -7
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -4
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -5
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
- package/docs/en/plugin/_meta.json +8 -7
- package/docs/en/plugin/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/cli-plugins/api.mdx +617 -0
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +139 -0
- package/docs/en/plugin/cli-plugins/migration.mdx +98 -0
- package/docs/en/plugin/introduction.mdx +119 -47
- package/docs/en/plugin/official/_meta.json +12 -0
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -0
- package/docs/en/plugin/official/cli-plugins.mdx +6 -0
- package/docs/en/plugin/official/rsbuild-plugins.mdx +3 -0
- package/docs/en/plugin/plugin-system.mdx +237 -0
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -0
- package/docs/en/plugin/runtime-plugins/api.mdx +165 -0
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +29 -0
- package/docs/en/plugin/runtime-plugins/migration.mdx +101 -0
- package/docs/en/plugin/server-plugins/api.mdx +3 -0
- package/docs/en/plugin/server-plugins/life-cycle.mdx +3 -0
- package/docs/zh/apis/app/hooks/src/app.mdx +18 -26
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/zh/apis/app/runtime/app/define-config.mdx +5 -0
- package/docs/zh/community/blog/v2-release-note.mdx +1 -1
- package/docs/zh/components/enable-micro-frontend.mdx +19 -12
- package/docs/zh/components/micro-runtime-config.mdx +3 -3
- package/docs/zh/components/reduck-notify.mdx +27 -0
- package/docs/zh/configure/app/plugins.mdx +2 -2
- package/docs/zh/configure/app/runtime/0-intro.mdx +67 -86
- package/docs/zh/configure/app/tools/esbuild.mdx +1 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -1
- package/docs/zh/configure/app/usage.mdx +44 -21
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +115 -0
- package/docs/zh/guides/basic-features/routes.mdx +0 -95
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +3 -5
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +4 -2
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/define-model.mdx +1 -4
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -5
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -4
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +7 -8
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -4
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -5
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -4
- package/docs/zh/plugin/_meta.json +8 -7
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +617 -0
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +139 -0
- package/docs/zh/plugin/cli-plugins/migration.mdx +98 -0
- package/docs/zh/plugin/introduction.mdx +92 -20
- package/docs/zh/plugin/official/_meta.json +12 -0
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +6 -0
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +3 -0
- package/docs/zh/plugin/plugin-system.mdx +239 -0
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -0
- package/docs/zh/plugin/runtime-plugins/api.mdx +166 -0
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +29 -0
- package/docs/zh/plugin/runtime-plugins/migration.mdx +101 -0
- package/docs/zh/plugin/server-plugins/api.mdx +3 -0
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +3 -0
- package/i18n.json +4 -0
- package/package.json +3 -2
- package/src/components/Footer/index.tsx +1 -1
- package/src/components/Mermaid/index.tsx +60 -0
- package/src/components/Mermaid/style.scss +221 -0
- package/docs/en/plugin/cli-plugins.mdx +0 -6
- package/docs/en/plugin/plugin-system/_meta.json +0 -10
- package/docs/en/plugin/plugin-system/extend.mdx +0 -163
- package/docs/en/plugin/plugin-system/hook-list.mdx +0 -711
- package/docs/en/plugin/plugin-system/hook.mdx +0 -188
- package/docs/en/plugin/plugin-system/implement.mdx +0 -243
- package/docs/en/plugin/plugin-system/introduction.mdx +0 -95
- package/docs/en/plugin/plugin-system/lifecycle.mdx +0 -16
- package/docs/en/plugin/plugin-system/plugin-api.mdx +0 -138
- package/docs/en/plugin/plugin-system/relationship.mdx +0 -119
- package/docs/en/plugin/rsbuild-plugins.mdx +0 -3
- package/docs/zh/plugin/cli-plugins.mdx +0 -6
- package/docs/zh/plugin/plugin-system/_meta.json +0 -10
- package/docs/zh/plugin/plugin-system/extend.mdx +0 -163
- package/docs/zh/plugin/plugin-system/hook-list.mdx +0 -715
- package/docs/zh/plugin/plugin-system/hook.mdx +0 -173
- package/docs/zh/plugin/plugin-system/implement.mdx +0 -250
- package/docs/zh/plugin/plugin-system/introduction.mdx +0 -94
- package/docs/zh/plugin/plugin-system/lifecycle.mdx +0 -16
- package/docs/zh/plugin/plugin-system/plugin-api.mdx +0 -138
- package/docs/zh/plugin/plugin-system/relationship.mdx +0 -119
- package/docs/zh/plugin/rsbuild-plugins.mdx +0 -4
- /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-bff.mdx +0 -0
- /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-ssg.mdx +0 -0
- /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-swc.mdx +0 -0
- /package/docs/en/plugin/{cli-plugins → official/cli-plugins}/plugin-tailwind.mdx +0 -0
- /package/docs/en/plugin/{rsbuild-plugins → official/rsbuild-plugins}/_meta.json +0 -0
- /package/docs/en/plugin/{rsbuild-plugins → official/rsbuild-plugins}/plugin-esbuild.mdx +0 -0
- /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-bff.mdx +0 -0
- /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-ssg.mdx +0 -0
- /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-swc.mdx +0 -0
- /package/docs/zh/plugin/{cli-plugins → official/cli-plugins}/plugin-tailwind.mdx +0 -0
- /package/docs/zh/plugin/{rsbuild-plugins → official/rsbuild-plugins}/_meta.json +0 -0
- /package/docs/zh/plugin/{rsbuild-plugins → official/rsbuild-plugins}/plugin-esbuild.mdx +0 -0
@@ -1,119 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 4
|
3
|
-
---
|
4
|
-
|
5
|
-
# Relationship
|
6
|
-
|
7
|
-
The plugin configuration object in Modern.js provides a series of fields to control plugin order, mutual exclusion, and other capabilities. The available fields are as follows:
|
8
|
-
|
9
|
-
- `name`: `string`, sets the name of the current plugin.
|
10
|
-
- `pre`: `string[]`, these plugins will be adjusted to be executed before the current plugin.
|
11
|
-
- `post`: `string[]`, these plugins will be adjusted to be executed after the current plugin.
|
12
|
-
- `rivals`: `string[]`, mutually exclusive plugins, an error will be thrown when encountering these plugins.
|
13
|
-
- `required`: `string[]`, required plugins, an error will be thrown when the corresponding plugin is not found in the plugin list.
|
14
|
-
- `usePlugin`: `CliPlugin[]`, registers other plugins.
|
15
|
-
|
16
|
-
The above parameters can be used to achieve plugin front, back, mutual exclusion, and mandatory logic.
|
17
|
-
|
18
|
-
## Plugin Sorting
|
19
|
-
|
20
|
-
Modern.js plugins achieve plugin sorting functionality through the `pre` and `post` parameters.
|
21
|
-
|
22
|
-
### Pre
|
23
|
-
|
24
|
-
By default, plugins are executed in the order they are added. You can declare preceding plugins to be executed by using the `pre` field.
|
25
|
-
|
26
|
-
For example, there are the following two plugins:
|
27
|
-
|
28
|
-
```ts title=foo.ts
|
29
|
-
const foo = {
|
30
|
-
name: 'plugin-foo',
|
31
|
-
};
|
32
|
-
```
|
33
|
-
|
34
|
-
```ts title=bar.ts
|
35
|
-
const bar = {
|
36
|
-
name: 'plugin-bar',
|
37
|
-
pre: ['plugin-foo'],
|
38
|
-
};
|
39
|
-
```
|
40
|
-
|
41
|
-
The `bar` plugin configures the `foo` plugin in the `pre` field, so the'foo' plugin must be executed before the `bar` plugin.
|
42
|
-
|
43
|
-
### Post
|
44
|
-
|
45
|
-
Declare succeeding plugins to be executed by using the `post` field.
|
46
|
-
|
47
|
-
```ts title=foo.ts
|
48
|
-
const foo = {
|
49
|
-
name: 'plugin-foo',
|
50
|
-
};
|
51
|
-
```
|
52
|
-
|
53
|
-
```ts title=bar.ts
|
54
|
-
const bar = {
|
55
|
-
name: 'plugin-bar',
|
56
|
-
post: ['plugin-foo'],
|
57
|
-
};
|
58
|
-
```
|
59
|
-
|
60
|
-
If you use the `post` parameter in the `bar` plugin's configuration and set it to `['foo']`, then the `foo` plugin will be executed after the `bar` plugin.
|
61
|
-
|
62
|
-
## rivals
|
63
|
-
|
64
|
-
The rivals field can be used to declare a mutual exclusion relationship between plugins.
|
65
|
-
|
66
|
-
there are two plugin:
|
67
|
-
|
68
|
-
```ts title=foo.ts
|
69
|
-
const foo = {
|
70
|
-
name: 'plugin-foo',
|
71
|
-
};
|
72
|
-
```
|
73
|
-
|
74
|
-
```ts title=bar.ts
|
75
|
-
const bar = {
|
76
|
-
name: 'plugin-bar',
|
77
|
-
rivals: ['plugin-foo'],
|
78
|
-
};
|
79
|
-
```
|
80
|
-
|
81
|
-
The `bar` plugin has been configured with the `foo` plugin in the `rivals` field, therefore an error will be thrown if both the `foo` and `bar` plugins are added simultaneously.
|
82
|
-
|
83
|
-
## required
|
84
|
-
|
85
|
-
The `required` field can be used to declare a dependency relationship between plugins.
|
86
|
-
|
87
|
-
there are two plugin:
|
88
|
-
|
89
|
-
```ts title=foo.ts
|
90
|
-
const foo = {
|
91
|
-
name: 'plugin-foo',
|
92
|
-
};
|
93
|
-
```
|
94
|
-
|
95
|
-
```ts title=bar.ts
|
96
|
-
const bar = {
|
97
|
-
name: 'plugin-bar',
|
98
|
-
required: ['plugin-foo'],
|
99
|
-
};
|
100
|
-
```
|
101
|
-
|
102
|
-
The `bar` plugin has been configured with the `foo` plugin in the `required` field. Therefore, an error will be thrown when using the `bar` plugin if the `foo` plugin is not configured.
|
103
|
-
|
104
|
-
## Register Plugin
|
105
|
-
|
106
|
-
When there is a dependency relationship between plugins, we can also actively register another plugin in a plugin by using `usePlugin`.
|
107
|
-
|
108
|
-
```ts title=foo.ts
|
109
|
-
const foo = () => ({
|
110
|
-
name: 'plugin-foo',
|
111
|
-
});
|
112
|
-
|
113
|
-
const bar = () => ({
|
114
|
-
name: 'plugin-bar',
|
115
|
-
usePlugin: [foo()],
|
116
|
-
});
|
117
|
-
```
|
118
|
-
|
119
|
-
When the user configures the `bar` plugin, the foo plugin will also be automatically registered and activated. The user does not need to register the `foo` plugin separately.
|
@@ -1,6 +0,0 @@
|
|
1
|
-
# 概览
|
2
|
-
|
3
|
-
- [@modern-js/plugin-tailwindcss](/plugin/cli-plugins/plugin-tailwind):提供使用 Tailwind CSS 样式的能力。
|
4
|
-
- [@modern-js/plugin-bff](/plugin/cli-plugins/plugin-bff):提供 BFF 服务,一体化调用的能力。
|
5
|
-
- [@modern-js/plugin-ssg](/plugin/cli-plugins/plugin-bff):提供静态站点生成的能力。
|
6
|
-
- [@modern-js/plugin-swc](/plugin/cli-plugins/plugin-swc):提供 SWC 编译支持。
|
@@ -1,163 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 5
|
3
|
-
---
|
4
|
-
|
5
|
-
# 扩展插件 Hook
|
6
|
-
|
7
|
-
本小节介绍如何通过动态注册 [Hook 模型](/plugin/plugin-system/hook) 的方式来扩展插件 Hook。
|
8
|
-
|
9
|
-
## 示例
|
10
|
-
|
11
|
-
这里我们用一个简单的例子演示一下。假设我们要添加一些管理控制台输出信息的 Hook。
|
12
|
-
|
13
|
-
首先我们初始化一个空的项目文件,并添加基础依赖:
|
14
|
-
|
15
|
-
```bash
|
16
|
-
$ npx @modern-js/create@latest modern-js-demo
|
17
|
-
```
|
18
|
-
|
19
|
-
### 创建 Hook
|
20
|
-
|
21
|
-
我们先创建一个 Hook 模型:
|
22
|
-
|
23
|
-
```ts title=config/plugin/myPlugin.ts
|
24
|
-
import { createWaterfall } from '@modern-js/plugin';
|
25
|
-
|
26
|
-
const message = createWaterfall<string[]>();
|
27
|
-
```
|
28
|
-
|
29
|
-
然后注册它:
|
30
|
-
|
31
|
-
```ts title=config/plugin/myPlugin.ts
|
32
|
-
import type { CliPlugin } from '@modern-js/core';
|
33
|
-
|
34
|
-
export const myPlugin = (): CliPlugin => ({
|
35
|
-
name: 'my-plugin',
|
36
|
-
|
37
|
-
registerHook: {
|
38
|
-
message,
|
39
|
-
},
|
40
|
-
});
|
41
|
-
```
|
42
|
-
|
43
|
-
添加 Hook 类型:
|
44
|
-
|
45
|
-
```ts title=config/plugin/myPlugin.ts
|
46
|
-
declare module '@modern-js/core' {
|
47
|
-
export interface Hooks {
|
48
|
-
message: typeof message;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
```
|
52
|
-
|
53
|
-
### 使用 Hook
|
54
|
-
|
55
|
-
创建插件,通过 `commands` Hook 函数,添加命令处理逻辑:
|
56
|
-
|
57
|
-
```ts title=config/plugin/myPlugin.ts
|
58
|
-
import type { CliPlugin } from '@modern-js/core';
|
59
|
-
|
60
|
-
export const myPlugin = (): CliPlugin => ({
|
61
|
-
name: 'my-plugin',
|
62
|
-
|
63
|
-
setup(api) {
|
64
|
-
return {
|
65
|
-
commands({ program }) {
|
66
|
-
program.command('message').action(async () => {
|
67
|
-
const hookRunners = api.useHookRunners();
|
68
|
-
const messages = hookRunners.message([]);
|
69
|
-
console.log(messages.join('\n'));
|
70
|
-
});
|
71
|
-
},
|
72
|
-
};
|
73
|
-
},
|
74
|
-
});
|
75
|
-
```
|
76
|
-
|
77
|
-
最后 `config/plugin/myPlugin.ts` 的状态是:
|
78
|
-
|
79
|
-
```ts title=config/plugin/myPlugin.ts
|
80
|
-
import { createWaterfall } from '@modern-js/plugin';
|
81
|
-
import type { CliPlugin } from '@modern-js/core';
|
82
|
-
|
83
|
-
const message = createWaterfall<string[]>();
|
84
|
-
|
85
|
-
export const myPlugin = (): CliPlugin => ({
|
86
|
-
name: 'my-plugin',
|
87
|
-
|
88
|
-
registerHook: {
|
89
|
-
message,
|
90
|
-
},
|
91
|
-
|
92
|
-
setup(api) {
|
93
|
-
return {
|
94
|
-
commands({ program }) {
|
95
|
-
program.command('message').action(async () => {
|
96
|
-
const hookRunners = api.useHookRunners();
|
97
|
-
const messages = hookRunners.message([]);
|
98
|
-
console.log(messages.join('\n'));
|
99
|
-
});
|
100
|
-
},
|
101
|
-
};
|
102
|
-
},
|
103
|
-
});
|
104
|
-
|
105
|
-
declare module '@modern-js/core' {
|
106
|
-
export interface Hooks {
|
107
|
-
message: typeof message;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
```
|
111
|
-
|
112
|
-
然后在 `modern.config.ts` 中添加这个插件:
|
113
|
-
|
114
|
-
```ts title="modern.config.ts"
|
115
|
-
import { defineConfig } from '@modern-js/app-tools';
|
116
|
-
import { myPlugin } from './config/plugin/myPlugin';
|
117
|
-
|
118
|
-
export default defineConfig({
|
119
|
-
plugins: [myPlugin()],
|
120
|
-
});
|
121
|
-
```
|
122
|
-
|
123
|
-
这时运行 `npx modern message` 就会执行相关逻辑,但由于没有收集到任何信息,所以控制台输出为空。
|
124
|
-
|
125
|
-
那这里我们添加一个:
|
126
|
-
|
127
|
-
```ts title=config/plugin/otherPlugin.ts
|
128
|
-
import type { CliPlugin } from '@modern-js/core';
|
129
|
-
|
130
|
-
export const otherPlugin = (): CliPlugin => ({
|
131
|
-
name: 'other-plugin',
|
132
|
-
|
133
|
-
setup(api) {
|
134
|
-
return {
|
135
|
-
message(list) {
|
136
|
-
return [...list, '[foo] line 0', '[foo] line 1'];
|
137
|
-
},
|
138
|
-
};
|
139
|
-
},
|
140
|
-
});
|
141
|
-
```
|
142
|
-
|
143
|
-
将它添加到配置中:
|
144
|
-
|
145
|
-
```ts title="modern.config.ts"
|
146
|
-
import { defineConfig } from '@modern-js/app-tools';
|
147
|
-
import { myPlugin } from './config/plugin/myPlugin';
|
148
|
-
import { otherPlugin } from './config/plugin/otherPlugin';
|
149
|
-
|
150
|
-
export default defineConfig({
|
151
|
-
plugins: [myPlugin(), otherPlugin()],
|
152
|
-
});
|
153
|
-
```
|
154
|
-
|
155
|
-
这时运行 `npx modern message` 就可以在控制台看到信息了:
|
156
|
-
|
157
|
-
```bash
|
158
|
-
$ modern message
|
159
|
-
[foo] line 0
|
160
|
-
[foo] line 1
|
161
|
-
```
|
162
|
-
|
163
|
-
以上面这种方式就可以扩展出拥有各种能力的插件 Hook。
|