@modern-js/main-doc 2.7.0 → 2.8.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +17 -0
- package/README.md +2 -2
- package/en/apis/app/commands.mdx +2 -0
- package/en/apis/app/runtime/model/connect.mdx +1 -1
- package/en/apis/app/runtime/model/model_.mdx +1 -1
- package/en/apis/app/runtime/model/use-model.mdx +1 -1
- package/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/en/apis/app/runtime/web-server/middleware.mdx +33 -9
- package/en/components/enable-bff.mdx +4 -4
- package/en/components/init-rspack-app.mdx +7 -0
- package/en/configure/app/bff/enable-handle-web.mdx +24 -0
- package/en/configure/app/server/enable-framework-ext.mdx +1 -1
- package/en/guides/advanced-features/bff/_category_.json +1 -1
- package/en/guides/advanced-features/eslint.mdx +30 -32
- package/en/guides/advanced-features/low-level.mdx +1 -1
- package/en/guides/advanced-features/rspack-start.mdx +13 -17
- package/en/guides/advanced-features/web-server.mdx +87 -20
- package/en/guides/concept/builder.mdx +1 -1
- package/en/guides/topic-detail/framework-plugin/extend.mdx +20 -19
- package/en/guides/topic-detail/framework-plugin/hook-list.mdx +156 -155
- package/en/guides/topic-detail/framework-plugin/hook.mdx +58 -43
- package/en/guides/topic-detail/framework-plugin/implement.mdx +47 -49
- package/en/guides/topic-detail/framework-plugin/introduction.mdx +22 -23
- package/en/guides/topic-detail/framework-plugin/plugin-api.mdx +13 -13
- package/en/guides/topic-detail/framework-plugin/relationship.mdx +30 -30
- package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
- package/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +17 -17
- package/en/guides/topic-detail/micro-frontend/c02-development.mdx +76 -78
- package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +57 -51
- package/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +11 -11
- package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +13 -13
- package/en/guides/topic-detail/model/auto-actions.mdx +18 -21
- package/en/guides/topic-detail/model/computed-state.mdx +27 -25
- package/en/guides/topic-detail/model/define-model.mdx +14 -14
- package/en/guides/topic-detail/model/faq.mdx +12 -13
- package/en/guides/topic-detail/model/manage-effects.mdx +43 -52
- package/en/guides/topic-detail/model/model-communicate.mdx +47 -45
- package/en/guides/topic-detail/model/performance.mdx +22 -23
- package/en/guides/topic-detail/model/quick-start.mdx +29 -28
- package/en/guides/topic-detail/model/redux-integration.mdx +7 -7
- package/en/guides/topic-detail/model/test-model.mdx +11 -11
- package/en/guides/topic-detail/model/typescript-best-practice.mdx +16 -15
- package/en/guides/topic-detail/model/use-model.mdx +40 -45
- package/en/guides/topic-detail/model/use-out-of-modernjs.mdx +16 -16
- package/en/guides/troubleshooting/cli.mdx +2 -2
- package/package.json +5 -5
- package/zh/apis/app/commands.mdx +2 -0
- package/zh/apis/app/runtime/model/connect.mdx +1 -1
- package/zh/apis/app/runtime/model/model_.mdx +1 -1
- package/zh/apis/app/runtime/model/use-model.mdx +1 -1
- package/zh/apis/app/runtime/web-server/hook.mdx +2 -4
- package/zh/apis/app/runtime/web-server/middleware.mdx +30 -10
- package/zh/apis/monorepo/commands/gen-release-note.mdx +3 -3
- package/zh/components/enable-bff.mdx +4 -4
- package/zh/components/init-rspack-app.mdx +7 -0
- package/zh/components/release-note.mdx +1 -1
- package/zh/configure/app/bff/enable-handle-web.mdx +24 -0
- package/zh/configure/app/server/enable-framework-ext.mdx +1 -1
- package/zh/guides/advanced-features/bff/_category_.json +1 -1
- package/zh/guides/advanced-features/rspack-start.mdx +13 -17
- package/zh/guides/advanced-features/web-server.mdx +81 -16
- package/zh/guides/concept/builder.mdx +1 -1
- package/zh/guides/topic-detail/changesets/github.mdx +2 -2
- package/zh/guides/topic-detail/changesets/release-note.mdx +1 -1
- package/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +2 -2
- package/zh/guides/topic-detail/generator/plugin/develop.mdx +1 -1
- package/zh/guides/topic-detail/model/faq.mdx +1 -1
- package/zh/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/zh/guides/topic-detail/model/performance.mdx +1 -1
- package/zh/guides/topic-detail/model/quick-start.mdx +2 -2
- package/zh/guides/topic-detail/model/use-model.mdx +3 -3
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: Extending
|
|
3
3
|
sidebar_position: 5
|
|
4
4
|
---
|
|
5
|
-
#
|
|
5
|
+
# Extending Plugin Hooks
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This section describes how to extend plugin Hooks by dynamically registering [Hook models](/guides/topic-detail/framework-plugin/hook).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Example
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Here is a simple example to demonstrate how to extend plugin Hooks by adding Hooks that manage console output.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
First, we initialize an empty project file and add basic dependencies:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
$ npx @modern-js/create modern-js-demo
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
###
|
|
19
|
+
### Creating Hooks
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
First, let's create a Hook model:
|
|
22
22
|
|
|
23
23
|
```ts title=config/plugin/myPlugin.ts
|
|
24
24
|
import { createWaterfall } from '@modern-js/plugin';
|
|
@@ -26,7 +26,7 @@ import { createWaterfall } from '@modern-js/plugin';
|
|
|
26
26
|
const message = createWaterfall<string[]>();
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
then register:
|
|
30
30
|
|
|
31
31
|
```ts title=config/plugin/myPlugin.ts
|
|
32
32
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -40,7 +40,7 @@ export default (): CliPlugin => ({
|
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
add Hook types:
|
|
44
44
|
|
|
45
45
|
```ts title=config/plugin/myPlugin.ts
|
|
46
46
|
declare module '@modern-js/core' {
|
|
@@ -50,9 +50,9 @@ declare module '@modern-js/core' {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
###
|
|
53
|
+
### Using Hooks
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Create a plugin and add command handling logic through the `commands` Hook function:
|
|
56
56
|
|
|
57
57
|
```ts title=config/plugin/myPlugin.ts
|
|
58
58
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -74,7 +74,7 @@ export default (): CliPlugin => ({
|
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
now `config/plugin/myPlugin.ts` is:
|
|
78
78
|
|
|
79
79
|
```ts title=config/plugin/myPlugin.ts
|
|
80
80
|
import { createWaterfall } from '@modern-js/plugin';
|
|
@@ -109,7 +109,7 @@ declare module '@modern-js/core' {
|
|
|
109
109
|
}
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
Then add this plugin in `modern.config.ts`:
|
|
113
113
|
|
|
114
114
|
```ts title="modern.config.ts"
|
|
115
115
|
import { defineConfig } from '@modern-js/app-tools';
|
|
@@ -120,9 +120,9 @@ export default defineConfig({
|
|
|
120
120
|
});
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
Now, run `npx modern message`, and the related logic will be executed, but no information is collected, so the console output is empty.
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
add:
|
|
126
126
|
|
|
127
127
|
```ts title=config/plugin/otherPlugin.ts
|
|
128
128
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -140,7 +140,7 @@ export default (): CliPlugin => ({
|
|
|
140
140
|
});
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
add to config:
|
|
144
144
|
|
|
145
145
|
```ts title="modern.config.ts"
|
|
146
146
|
import { defineConfig } from '@modern-js/app-tools';
|
|
@@ -152,7 +152,7 @@ export default defineConfig({
|
|
|
152
152
|
});
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
run `npx modern message`, then we can get follow in console:
|
|
156
156
|
|
|
157
157
|
```bash
|
|
158
158
|
$ modern message
|
|
@@ -160,4 +160,5 @@ $ modern message
|
|
|
160
160
|
[foo] line 1
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
By using the above approach, you can extend plugin Hooks with various capabilities.
|
|
164
|
+
|