@modern-js/main-doc 2.0.0-canary.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/_category_.json +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +62 -31
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/router.md +174 -375
- package/en/docusaurus-plugin-content-docs/current/components/enable-micro-frontend.md +13 -0
- package/en/docusaurus-plugin-content-docs/current/components/micro-master-manifest-config.md +15 -0
- package/en/docusaurus-plugin-content-docs/current/components/micro-runtime-config.md +18 -0
- package/en/docusaurus-plugin-content-docs/current/components/router-legacy-tip.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/auto-load-plugin.md +62 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/deploy/microFrontend.md +54 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/ssg.md +226 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/master-app.md +20 -39
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +17 -4
- package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/state.md +17 -4
- package/en/docusaurus-plugin-content-docs/current/configure/app/server/enable-framework-ext.md +47 -0
- package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/function.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/ssg.md +6 -2
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +0 -2
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/_category_.json +5 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/extend.md +162 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/hook-list.md +803 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/hook.md +169 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/implement.md +247 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/introduction.md +49 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/plugin-api.md +116 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/relationship.md +118 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/common.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/module.md +3 -1
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/mwa.md +1 -9
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/project.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c02-development.md +191 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/micro-frontend/c05-mixed-stack.md +24 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/auto-actions.md +90 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/computed-state.md +151 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/define-model.md +66 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/faq.md +43 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/manage-effects.md +259 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/model-communicate.md +219 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/performance.md +173 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/quick-start.md +116 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/redux-integration.md +21 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/test-model.md +43 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/typescript-best-practice.md +71 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/use-model.md +244 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/model/use-out-of-modernjs.md +51 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/_category_.json +5 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c01-start.md +99 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c02-component.md +56 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c03-css.md +324 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c04-routes.md +169 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c05-loader.md +82 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c06-model.md +260 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c07-container.md +283 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/first-app/c08-entries.md +137 -0
- package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/_category_.json +1 -1
- package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/introduction.md +5 -3
- package/package.json +4 -4
- package/zh/apis/app/runtime/core/use-module-apps.md +2 -0
- package/zh/apis/app/runtime/router/router.md +169 -371
- package/zh/components/micro-master-manifest-config.md +15 -0
- package/zh/components/router-legacy-tip.md +1 -0
- package/zh/configure/app/auto-load-plugin.md +62 -0
- package/zh/configure/app/deploy/microFrontend.md +0 -10
- package/zh/configure/app/output/ssg.md +1 -5
- package/zh/configure/app/runtime/master-app.md +4 -18
- package/zh/configure/app/runtime/router.md +19 -4
- package/zh/configure/app/runtime/state.md +7 -7
- package/zh/configure/app/server/enable-framework-ext.md +47 -0
- package/zh/configure/app/server/port.md +1 -1
- package/zh/configure/app/tools/_category_.json +1 -1
- package/zh/guides/advanced-features/eslint.md +2 -1
- package/zh/guides/advanced-features/ssg.md +4 -0
- package/zh/guides/basic-features/data-fetch.md +1 -1
- package/zh/guides/basic-features/env-vars.md +1 -1
- package/zh/guides/basic-features/routes.md +0 -3
- package/zh/guides/topic-detail/generator/config/module.md +3 -1
- package/zh/guides/topic-detail/generator/config/mwa.md +1 -9
- package/zh/guides/topic-detail/model/quick-start.md +1 -1
- package/zh/tutorials/first-app/c06-model.md +5 -1
- package/zh/tutorials/first-app/c08-entries.md +1 -1
- package/zh/tutorials/foundations/introduction.md +5 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +0 -12
- package/en/docusaurus-plugin-content-docs/current/configure/app/bff/fetcher.md +0 -28
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -31
- package/en/docusaurus-plugin-content-docs/current/guides/overview.md +0 -11
- package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/basic.md +0 -8
- package/zh/apis/app/overview.md +0 -11
- package/zh/apis/monorepo/overview.md +0 -11
- package/zh/configure/app/bff/fetcher.md +0 -31
- package/zh/configure/app/dev/with-master-app.md +0 -32
- package/zh/guides/overview.md +0 -11
- package/zh/tutorials/foundations/basic.md +0 -8
package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/extend.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
---
|
2
|
+
title: 扩展插件 Hook
|
3
|
+
sidebar_position: 5
|
4
|
+
---
|
5
|
+
|
6
|
+
本小节介绍如何通过动态注册 [Hook 模型](/docs/guides/topic-detail/framework-plugin/hook) 的方式来扩展插件 Hook。
|
7
|
+
|
8
|
+
## 示例
|
9
|
+
|
10
|
+
这里我们用一个简单的例子演示一下。假设我们要添加一些管理控制台输出信息的 Hook。
|
11
|
+
|
12
|
+
首先我们初始化一个空的项目文件,并添加基础依赖:
|
13
|
+
|
14
|
+
```console
|
15
|
+
$ npx @modern-js/create modern-js-demo
|
16
|
+
```
|
17
|
+
|
18
|
+
### 创建 Hook
|
19
|
+
|
20
|
+
我们先创建一个 Hook 模型:
|
21
|
+
|
22
|
+
```ts title=config/plugin/MyPlugin.ts
|
23
|
+
import { createWaterfall } from '@modern-js/plugin';
|
24
|
+
|
25
|
+
const message = createWaterfall<string[]>();
|
26
|
+
```
|
27
|
+
|
28
|
+
然后注册它:
|
29
|
+
|
30
|
+
```ts title=config/plugin/MyPlugin.ts
|
31
|
+
import type { CliPlugin } from '@modern-js/core';
|
32
|
+
|
33
|
+
export default (): CliPlugin => ({
|
34
|
+
name: 'my-plugin',
|
35
|
+
|
36
|
+
registerHook: {
|
37
|
+
message,
|
38
|
+
},
|
39
|
+
});
|
40
|
+
```
|
41
|
+
|
42
|
+
添加 Hook 类型:
|
43
|
+
|
44
|
+
```ts title=config/plugin/MyPlugin.ts
|
45
|
+
declare module '@modern-js/core' {
|
46
|
+
export interface Hooks {
|
47
|
+
message: typeof message;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
### 使用 Hook
|
53
|
+
|
54
|
+
创建插件,通过 `commands` Hook 函数,添加命令处理逻辑:
|
55
|
+
|
56
|
+
```ts title=config/plugin/MyPlugin.ts
|
57
|
+
import type { CliPlugin } from '@modern-js/core';
|
58
|
+
|
59
|
+
export default (): CliPlugin => ({
|
60
|
+
name: 'my-plugin',
|
61
|
+
|
62
|
+
setup(api) {
|
63
|
+
return {
|
64
|
+
commands({ program }) {
|
65
|
+
program.command('message').action(async () => {
|
66
|
+
const hookRunners = api.useHookRunners();
|
67
|
+
const messages = hookRunners.message([]);
|
68
|
+
console.log(messages.join('\n'));
|
69
|
+
});
|
70
|
+
},
|
71
|
+
};
|
72
|
+
},
|
73
|
+
});
|
74
|
+
```
|
75
|
+
|
76
|
+
最后 `config/plugin/MyPlugin.ts` 的状态是:
|
77
|
+
|
78
|
+
```ts title=config/plugin/MyPlugin.ts
|
79
|
+
import { createWaterfall } from '@modern-js/plugin';
|
80
|
+
import type { CliPlugin } from '@modern-js/core';
|
81
|
+
|
82
|
+
const message = createWaterfall<string[]>();
|
83
|
+
|
84
|
+
export default (): CliPlugin => ({
|
85
|
+
name: 'my-plugin',
|
86
|
+
|
87
|
+
registerHook: {
|
88
|
+
message,
|
89
|
+
},
|
90
|
+
|
91
|
+
setup(api) {
|
92
|
+
return {
|
93
|
+
commands({ program }) {
|
94
|
+
program.command('message').action(async () => {
|
95
|
+
const hookRunners = api.useHookRunners();
|
96
|
+
const messages = hookRunners.message([]);
|
97
|
+
console.log(messages.join('\n'));
|
98
|
+
});
|
99
|
+
},
|
100
|
+
};
|
101
|
+
},
|
102
|
+
});
|
103
|
+
|
104
|
+
declare module '@modern-js/core' {
|
105
|
+
export interface Hooks {
|
106
|
+
message: typeof message;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
```
|
110
|
+
|
111
|
+
然后在 `modern.config.ts` 中添加这个插件:
|
112
|
+
|
113
|
+
```ts title="modern.config.ts"
|
114
|
+
import { defineConfig } from '@modern-js/app-tools';
|
115
|
+
import MyPlugin from './config/plugin/MyPlugin';
|
116
|
+
|
117
|
+
export default defineConfig({
|
118
|
+
plugins: [MyPlugin()],
|
119
|
+
});
|
120
|
+
```
|
121
|
+
|
122
|
+
这时运行 `npx modern message` 就会执行相关逻辑,但由于没有收集到任何信息,所以控制台输出为空。
|
123
|
+
|
124
|
+
那这里我们添加一个:
|
125
|
+
|
126
|
+
```ts title=config/plugin/OtherPlugin.ts
|
127
|
+
import type { CliPlugin } from '@modern-js/core';
|
128
|
+
|
129
|
+
export default (): CliPlugin => ({
|
130
|
+
name: 'my-plugin',
|
131
|
+
|
132
|
+
setup(api) {
|
133
|
+
return {
|
134
|
+
message(list) {
|
135
|
+
return [...list, '[foo] line 0', '[foo] line 1'];
|
136
|
+
},
|
137
|
+
};
|
138
|
+
},
|
139
|
+
});
|
140
|
+
```
|
141
|
+
|
142
|
+
将它添加到配置中:
|
143
|
+
|
144
|
+
```ts title="modern.config.ts"
|
145
|
+
import { defineConfig } from '@modern-js/app-tools';
|
146
|
+
import MyPlugin from './config/plugin/MyPlugin';
|
147
|
+
import OtherPlugin from './config/plugin/OtherPlugin';
|
148
|
+
|
149
|
+
export default defineConfig({
|
150
|
+
plugins: [MyPlugin(), OtherPlugin()],
|
151
|
+
});
|
152
|
+
```
|
153
|
+
|
154
|
+
这时运行 `npx modern message` 就可以在控制台看到信息了:
|
155
|
+
|
156
|
+
```console
|
157
|
+
$ modern message
|
158
|
+
[foo] line 0
|
159
|
+
[foo] line 1
|
160
|
+
```
|
161
|
+
|
162
|
+
以上面这种方式就可以扩展出拥有各种能力的插件 Hook。
|