@modern-js/main-doc 0.0.0-next-3ef832741 → 0.0.0-next-1678282721176
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/CHANGELOG.md +3 -2
- package/en/guides/advanced-features/eslint.mdx +30 -32
- 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/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 +3 -3
- package/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +2 -2
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Hook
|
|
2
|
+
title: Hook List
|
|
3
3
|
sidebar_position: 8
|
|
4
4
|
---
|
|
5
|
-
# Hook
|
|
5
|
+
# Hook List
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Modern.js exposes three types of plugins: CLI, Runtime, and Server.
|
|
8
8
|
|
|
9
9
|
## CLI
|
|
10
10
|
|
|
11
11
|
### `config`
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- Hook
|
|
16
|
-
-
|
|
17
|
-
-
|
|
13
|
+
- Functionality: Collect configuration
|
|
14
|
+
- Execution phase: After parsing the configuration in `modern.config.ts`
|
|
15
|
+
- Hook model: ParallelWorkflow
|
|
16
|
+
- Type: `ParallelWorkflow<void, unknown>`
|
|
17
|
+
- Example usage:
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -32,15 +32,15 @@ export default (): CliPlugin => ({
|
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
The collected configuration information will be collected and processed uniformly.
|
|
36
36
|
|
|
37
37
|
### `validateSchema`
|
|
38
38
|
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
- Hook
|
|
42
|
-
-
|
|
43
|
-
-
|
|
39
|
+
- Functionality: Collect the JSON schema used to validate user configurations in various plugins.
|
|
40
|
+
- Execution phase: After the `config` Hook has run.
|
|
41
|
+
- Hook model: ParallelWorkflow
|
|
42
|
+
- Type: `ParallelWorkflow<void, unknown>`
|
|
43
|
+
- Example usage:
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -62,9 +62,9 @@ export default (): CliPlugin => ({
|
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
The returned JSON Schema here is used to validate the configuration information in `modern.config.js`.
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
For example, the following JSON Schema is returned:
|
|
68
68
|
|
|
69
69
|
```json
|
|
70
70
|
{
|
|
@@ -75,7 +75,7 @@ export default (): CliPlugin => ({
|
|
|
75
75
|
}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
You can configure it in `modern.config.ts` like this:
|
|
79
79
|
|
|
80
80
|
```ts title="modern.config.ts"
|
|
81
81
|
export default defineConfig({
|
|
@@ -83,7 +83,7 @@ export default defineConfig({
|
|
|
83
83
|
});
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
If it is another type, validation will fail and an error will be reported. For example:
|
|
87
87
|
|
|
88
88
|
```ts title="modern.config.ts"
|
|
89
89
|
export default defineConfig({
|
|
@@ -91,7 +91,7 @@ export default defineConfig({
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
then throw error:
|
|
95
95
|
|
|
96
96
|
```sh
|
|
97
97
|
$ modern dev
|
|
@@ -102,11 +102,11 @@ $ modern dev
|
|
|
102
102
|
|
|
103
103
|
### `prepare`
|
|
104
104
|
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
- Hook
|
|
108
|
-
-
|
|
109
|
-
-
|
|
105
|
+
- Functionality: Preparatory process for running the main process.
|
|
106
|
+
- Execution phase: After configuration validation.
|
|
107
|
+
- Hook model: AsyncWorkflow
|
|
108
|
+
- Type: `AsyncWorkflow<void, void>`
|
|
109
|
+
- Example usage:
|
|
110
110
|
|
|
111
111
|
```ts
|
|
112
112
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -146,11 +146,11 @@ export default (): CliPlugin => ({
|
|
|
146
146
|
|
|
147
147
|
### `commands`
|
|
148
148
|
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
- Hook
|
|
152
|
-
-
|
|
153
|
-
-
|
|
149
|
+
- Functionality: Add new commands for the command.
|
|
150
|
+
- Execution phase: After the `prepare` Hook has run.
|
|
151
|
+
- Hook model: AsyncWorkflow
|
|
152
|
+
- Type: `AsyncWorkflow<{ program: Command; }, void>`
|
|
153
|
+
- Example usage:
|
|
154
154
|
|
|
155
155
|
```ts
|
|
156
156
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -169,7 +169,7 @@ export default (): CliPlugin => ({
|
|
|
169
169
|
});
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
Move the plugin to `modern.config.ts`:
|
|
173
173
|
|
|
174
174
|
```ts title="modern.config.ts"
|
|
175
175
|
import myPlugin from './config/plugin/myPlugin';
|
|
@@ -179,7 +179,7 @@ export default defineConfig({
|
|
|
179
179
|
});
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
run `modern foo`:
|
|
183
183
|
|
|
184
184
|
```sh
|
|
185
185
|
$ modern foo
|
|
@@ -188,11 +188,11 @@ foo
|
|
|
188
188
|
|
|
189
189
|
### `beforeExit`
|
|
190
190
|
|
|
191
|
-
-
|
|
192
|
-
-
|
|
193
|
-
- Hook
|
|
194
|
-
-
|
|
195
|
-
-
|
|
191
|
+
- Functionality: Reset some file states before exiting the process.
|
|
192
|
+
- Execution phase: Before the process exits.
|
|
193
|
+
- Hook model: AsyncWorkflow
|
|
194
|
+
- Type: `AsyncWorkflow<void, void>`
|
|
195
|
+
- Example usage:
|
|
196
196
|
|
|
197
197
|
```ts
|
|
198
198
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -210,11 +210,11 @@ export default (): CliPlugin => ({
|
|
|
210
210
|
|
|
211
211
|
### `beforeDev`
|
|
212
212
|
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
- Hook
|
|
216
|
-
-
|
|
217
|
-
-
|
|
213
|
+
- Functionality: Tasks before running the main dev process.
|
|
214
|
+
- Execution phase: Before the project starts when the `dev` command is run.
|
|
215
|
+
- Hook model: AsyncWorkflow
|
|
216
|
+
- Type: `AsyncWorkflow<void, unknown>`
|
|
217
|
+
- Example usage:
|
|
218
218
|
|
|
219
219
|
```ts
|
|
220
220
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -232,11 +232,11 @@ export default (): CliPlugin => ({
|
|
|
232
232
|
|
|
233
233
|
### `afterDev`
|
|
234
234
|
|
|
235
|
-
-
|
|
236
|
-
-
|
|
237
|
-
- Hook
|
|
238
|
-
-
|
|
239
|
-
-
|
|
235
|
+
- Function: Tasks to be executed after the main process of `dev` command
|
|
236
|
+
- Execution Stage: Executed after the project is started when running the `dev` command
|
|
237
|
+
- Hook Model: AsyncWorkflow
|
|
238
|
+
- Type: `AsyncWorkflow<void, unknown>`
|
|
239
|
+
- Usage Example:
|
|
240
240
|
|
|
241
241
|
```ts
|
|
242
242
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -254,11 +254,11 @@ export default (): CliPlugin => ({
|
|
|
254
254
|
|
|
255
255
|
### `beforeCreateCompiler`
|
|
256
256
|
|
|
257
|
-
-
|
|
258
|
-
-
|
|
259
|
-
- Hook
|
|
260
|
-
-
|
|
261
|
-
-
|
|
257
|
+
- Function: Provides access to the Webpack configuration used to create the Webpack Compiler within middleware functions.
|
|
258
|
+
- Execution Stage: Executed before creating the Webpack Compiler.
|
|
259
|
+
- Hook Model: AsyncWorkflow.
|
|
260
|
+
- Type: `AsyncWorkflow<{ webpackConfigs: Configuration[];}, unknown>`.
|
|
261
|
+
- Usage Example:
|
|
262
262
|
|
|
263
263
|
```ts
|
|
264
264
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -276,11 +276,11 @@ export default (): CliPlugin => ({
|
|
|
276
276
|
|
|
277
277
|
### `afterCreateCompiler`
|
|
278
278
|
|
|
279
|
-
-
|
|
280
|
-
-
|
|
281
|
-
- Hook
|
|
282
|
-
-
|
|
283
|
-
-
|
|
279
|
+
- Function: Provides access to the created Webpack Compiler within middleware functions.
|
|
280
|
+
- Execution Stage: Executed after creating the Webpack Compiler.
|
|
281
|
+
- Hook Model: AsyncWorkflow.
|
|
282
|
+
- Type: `AsyncWorkflow<{ compiler: Compiler | MultiCompiler | undefined; }, unknown>`.
|
|
283
|
+
- Usage Example:
|
|
284
284
|
|
|
285
285
|
```ts
|
|
286
286
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -298,11 +298,11 @@ export default (): CliPlugin => ({
|
|
|
298
298
|
|
|
299
299
|
### `beforePrintInstructions`
|
|
300
300
|
|
|
301
|
-
-
|
|
302
|
-
-
|
|
303
|
-
- Hook
|
|
304
|
-
-
|
|
305
|
-
-
|
|
301
|
+
- Function: Provides access to the log information that will be printed within middleware functions and allows modification of the log information.
|
|
302
|
+
- Execution Stage: Executed before printing the log information.
|
|
303
|
+
- Hook Model: AsyncWaterfall.
|
|
304
|
+
- Type: `AsyncWaterfall<{ instructions: string }>`
|
|
305
|
+
- Usage Example:
|
|
306
306
|
|
|
307
307
|
```ts
|
|
308
308
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -323,11 +323,11 @@ export default (): CliPlugin => ({
|
|
|
323
323
|
|
|
324
324
|
### `beforeBuild`
|
|
325
325
|
|
|
326
|
-
-
|
|
327
|
-
-
|
|
328
|
-
- Hook
|
|
329
|
-
-
|
|
330
|
-
-
|
|
326
|
+
- Function: Tasks to be executed before the main process of the `build` command, provides access to the Webpack configuration used for building.
|
|
327
|
+
- Execution Stage: Executed before starting the project build when running the `build` command.
|
|
328
|
+
- Hook Model: AsyncWorkflow.
|
|
329
|
+
- Type: `AsyncWorkflow<{ webpackConfigs: Configuration[]; }>`.
|
|
330
|
+
- Usage Example:
|
|
331
331
|
|
|
332
332
|
```ts
|
|
333
333
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -345,11 +345,11 @@ export default (): CliPlugin => ({
|
|
|
345
345
|
|
|
346
346
|
### `afterBuild`
|
|
347
347
|
|
|
348
|
-
-
|
|
349
|
-
-
|
|
350
|
-
- Hook
|
|
351
|
-
-
|
|
352
|
-
-
|
|
348
|
+
- Function: Tasks to be executed after the main process of the `build` command.
|
|
349
|
+
- Execution Stage: Executed after the project build is completed when running the `build` command.
|
|
350
|
+
- Hook Model: AsyncWorkflow.
|
|
351
|
+
- Type: `AsyncWorkflow<void, unknown>`.
|
|
352
|
+
- Usage Example:
|
|
353
353
|
|
|
354
354
|
```ts
|
|
355
355
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -367,11 +367,11 @@ export default (): CliPlugin => ({
|
|
|
367
367
|
|
|
368
368
|
### `modifyEntryImports`
|
|
369
369
|
|
|
370
|
-
-
|
|
371
|
-
-
|
|
372
|
-
- Hook
|
|
373
|
-
-
|
|
374
|
-
-
|
|
370
|
+
- Function: Used for modifying or adding `import` statements in the generated entry files.
|
|
371
|
+
- Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
|
|
372
|
+
- Hook Model: AsyncWaterfall.
|
|
373
|
+
- Type: `AsyncWaterfall<{ imports: ImportStatement[]; entrypoint: Entrypoint; }>`
|
|
374
|
+
- Usage Example:
|
|
375
375
|
|
|
376
376
|
```ts
|
|
377
377
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -380,7 +380,7 @@ export default (): CliPlugin => ({
|
|
|
380
380
|
setup(api) {
|
|
381
381
|
return {
|
|
382
382
|
modifyEntryImports({ entrypoint, imports }) {
|
|
383
|
-
//
|
|
383
|
+
// add `import React from 'React'`
|
|
384
384
|
imports.push({
|
|
385
385
|
value: 'react',
|
|
386
386
|
specifiers: [
|
|
@@ -426,11 +426,11 @@ export default (): CliPlugin => ({
|
|
|
426
426
|
|
|
427
427
|
### `modifyEntryRuntimePlugins`
|
|
428
428
|
|
|
429
|
-
-
|
|
430
|
-
-
|
|
431
|
-
- Hook
|
|
432
|
-
-
|
|
433
|
-
-
|
|
429
|
+
- Function: Used for adding or modifying [Runtime plugins](#Runtime) in the generated entry files.
|
|
430
|
+
- Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
|
|
431
|
+
- Hook Model: AsyncWaterfall.
|
|
432
|
+
- Type: `AsyncWaterfall<{ entrypoint: Entrypoint; plugins: RuntimePlugin[]; }>`
|
|
433
|
+
- Usage Example:
|
|
434
434
|
|
|
435
435
|
```ts
|
|
436
436
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -461,11 +461,11 @@ export default (): CliPlugin => ({
|
|
|
461
461
|
|
|
462
462
|
### `modifyEntryRenderFunction`
|
|
463
463
|
|
|
464
|
-
-
|
|
465
|
-
-
|
|
466
|
-
- Hook
|
|
467
|
-
-
|
|
468
|
-
-
|
|
464
|
+
- Function: Used for modifying the `render` function in the generated entry files.
|
|
465
|
+
- Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
|
|
466
|
+
- Hook Model: AsyncWaterfall.
|
|
467
|
+
- Type: `AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
|
|
468
|
+
- Usage Example:
|
|
469
469
|
|
|
470
470
|
```ts
|
|
471
471
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -487,11 +487,11 @@ export default (): CliPlugin => ({
|
|
|
487
487
|
|
|
488
488
|
### `modifyFileSystemRoutes`
|
|
489
489
|
|
|
490
|
-
-
|
|
491
|
-
-
|
|
492
|
-
- Hook
|
|
493
|
-
-
|
|
494
|
-
-
|
|
490
|
+
- Function: Used for modifying the content of the generated front-end page routing files, which must be serializable.
|
|
491
|
+
- Execution Stage: Executed before generating the front-end routing files, triggered during the [`prepare`](#prepare) stage.
|
|
492
|
+
- Hook Model: AsyncWaterfall.
|
|
493
|
+
- Type: `AsyncWaterfall<{ entrypoint: Entrypoint; routes: Route[]; }>`
|
|
494
|
+
- Usage Example:
|
|
495
495
|
|
|
496
496
|
```tsx
|
|
497
497
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -517,15 +517,15 @@ export default (): CliPlugin => ({
|
|
|
517
517
|
});
|
|
518
518
|
```
|
|
519
519
|
|
|
520
|
-
|
|
520
|
+
This adds a new page route for the front-end.
|
|
521
521
|
|
|
522
522
|
### `modifyServerRoutes`
|
|
523
523
|
|
|
524
|
-
-
|
|
525
|
-
-
|
|
526
|
-
- Hook
|
|
527
|
-
-
|
|
528
|
-
-
|
|
524
|
+
- Function: Used for modifying the content of the generated server routes.
|
|
525
|
+
- Execution Stage: Executed before generating the server routing files, triggered during the [`prepare`](#prepare) stage.
|
|
526
|
+
- Hook Model: AsyncWaterfall.
|
|
527
|
+
- Type: `AsyncWaterfall<{ routes: ServerRoute[]; }>`
|
|
528
|
+
- Usage Example:
|
|
529
529
|
|
|
530
530
|
```ts
|
|
531
531
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -554,11 +554,11 @@ export default (): CliPlugin => ({
|
|
|
554
554
|
|
|
555
555
|
### `modifyAsyncEntry`
|
|
556
556
|
|
|
557
|
-
-
|
|
558
|
-
-
|
|
559
|
-
- Hook
|
|
560
|
-
-
|
|
561
|
-
-
|
|
557
|
+
- Function: Used for modifying the asynchronous module that wraps the entry file, see [source.enableAsyncEntry](/configure/app/source/enable-async-entry).
|
|
558
|
+
- Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
|
|
559
|
+
- Hook Model: AsyncWaterfall.
|
|
560
|
+
- Type: `AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
|
|
561
|
+
- Usage Example:
|
|
562
562
|
|
|
563
563
|
```ts
|
|
564
564
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -580,11 +580,11 @@ export default (): CliPlugin => ({
|
|
|
580
580
|
|
|
581
581
|
### `htmlPartials`
|
|
582
582
|
|
|
583
|
-
-
|
|
584
|
-
-
|
|
585
|
-
- Hook
|
|
586
|
-
-
|
|
587
|
-
-
|
|
583
|
+
- Function: Used for customizing the generated HTML page template.
|
|
584
|
+
- Execution Stage: Triggered during the [`prepare`](#prepare) stage.
|
|
585
|
+
- Hook Model: AsyncWaterfall.
|
|
586
|
+
- Type: `AsyncWaterfall<{ entrypoint: Entrypoint; partials: HtmlPartials; }>`
|
|
587
|
+
- Usage Example:
|
|
588
588
|
|
|
589
589
|
```ts
|
|
590
590
|
import type { CliPlugin } from '@modern-js/core';
|
|
@@ -604,24 +604,24 @@ export default (): CliPlugin => ({
|
|
|
604
604
|
});
|
|
605
605
|
```
|
|
606
606
|
|
|
607
|
-
|
|
607
|
+
This adds a new Script tag to the HTML template.
|
|
608
608
|
|
|
609
609
|
## Server
|
|
610
610
|
|
|
611
611
|
:::note
|
|
612
|
-
|
|
613
|
-
|
|
612
|
+
The Server plugin is currently not fully opened, and the API is not guaranteed to be stable. Use with caution.
|
|
614
613
|
:::
|
|
615
614
|
|
|
616
|
-
|
|
615
|
+
Plugins are also supported in the Server section of the application project. The hook will provide hooks for specific stage calls and special functionality.
|
|
617
616
|
|
|
618
617
|
### `create`
|
|
619
618
|
|
|
620
|
-
-
|
|
621
|
-
-
|
|
622
|
-
- Hook
|
|
623
|
-
-
|
|
624
|
-
-
|
|
619
|
+
- Function: In the middleware function, you will get the measurement tool configuration `measureOptions` and log tool configuration `loggerOptions` used for Server initialization, and return a custom measurement tool `measure` and log tool configuration `logger`.
|
|
620
|
+
- Execution Stage: Server initialization.
|
|
621
|
+
- Hook Model: AsyncPipeline.
|
|
622
|
+
- Type: `AsyncPipeline<ServerInitInput, InitExtension>`
|
|
623
|
+
- Usage Example:
|
|
624
|
+
|
|
625
625
|
|
|
626
626
|
```ts
|
|
627
627
|
import type { ServerPlugin } from '@modern-js/server-core';
|
|
@@ -639,11 +639,11 @@ export default (): ServerPlugin => ({
|
|
|
639
639
|
|
|
640
640
|
### `prepareWebServer`
|
|
641
641
|
|
|
642
|
-
-
|
|
643
|
-
-
|
|
644
|
-
- Hook
|
|
645
|
-
-
|
|
646
|
-
-
|
|
642
|
+
- Function: Sets the handling function for the Web route. In the middleware function, you can get the front-end middleware of the Web server.
|
|
643
|
+
- Execution Stage: When the request arrives.
|
|
644
|
+
- Hook Model: AsyncPipeline.
|
|
645
|
+
- Type: `AsyncPipeline<WebServerStartInput, Adapter>`
|
|
646
|
+
- Usage Example:
|
|
647
647
|
|
|
648
648
|
```ts
|
|
649
649
|
import type { ServerPlugin } from '@modern-js/server-core';
|
|
@@ -665,11 +665,11 @@ export default (): ServerPlugin => ({
|
|
|
665
665
|
|
|
666
666
|
### `prepareApiServer`
|
|
667
667
|
|
|
668
|
-
-
|
|
669
|
-
-
|
|
670
|
-
- Hook
|
|
671
|
-
-
|
|
672
|
-
-
|
|
668
|
+
- Function: Sets the handling function for the API route. In the middleware function, you can get the front-end middleware of the API server.
|
|
669
|
+
- Execution Stage: When the request arrives and matches the BFF basename.
|
|
670
|
+
- Hook Model: AsyncPipeline.
|
|
671
|
+
- Type: `AsyncPipeline<APIServerStartInput, Adapter>`
|
|
672
|
+
- Usage Example:
|
|
673
673
|
|
|
674
674
|
```ts
|
|
675
675
|
import type { ServerPlugin } from '@modern-js/server-core';
|
|
@@ -692,19 +692,18 @@ export default (): ServerPlugin => ({
|
|
|
692
692
|
## Runtime
|
|
693
693
|
|
|
694
694
|
:::note
|
|
695
|
-
|
|
696
|
-
|
|
695
|
+
The Runtime plugin is currently not fully opened, and the API is not guaranteed to be stable. Use with caution.
|
|
697
696
|
:::
|
|
698
697
|
|
|
699
|
-
Runtime
|
|
698
|
+
The Runtime plugin is mainly used for developers to modify the components and elements that need to be rendered, and customize the rendering process on the server and client side.
|
|
700
699
|
|
|
701
700
|
### `init`
|
|
702
701
|
|
|
703
|
-
-
|
|
704
|
-
-
|
|
705
|
-
- Hook
|
|
706
|
-
-
|
|
707
|
-
-
|
|
702
|
+
- Function: Executes `App.init`.
|
|
703
|
+
- Execution Stage: Rendering (SSR/CSR).
|
|
704
|
+
- Hook Model: AsyncPipeline.
|
|
705
|
+
- Type: `AsyncPipeline<{ context: RuntimeContext; }, unknown>`
|
|
706
|
+
- Usage Example:
|
|
708
707
|
|
|
709
708
|
```ts
|
|
710
709
|
import type { Plugin } from '@modern-js/runtime';
|
|
@@ -723,11 +722,11 @@ export default (): Plugin => ({
|
|
|
723
722
|
|
|
724
723
|
### `hoc`
|
|
725
724
|
|
|
726
|
-
-
|
|
727
|
-
-
|
|
728
|
-
- Hook
|
|
729
|
-
-
|
|
730
|
-
-
|
|
725
|
+
- Function: Modifies the components that need to be rendered.
|
|
726
|
+
- Execution Stage: Rendering (SSR/CSR).
|
|
727
|
+
- Hook Model: Pipeline.
|
|
728
|
+
- Type: `Pipeline<{ App: React.ComponentType<any>; }, React.ComponentType<any>>`
|
|
729
|
+
- Usage Example:
|
|
731
730
|
|
|
732
731
|
```ts
|
|
733
732
|
import { createContext } from 'react';
|
|
@@ -755,11 +754,11 @@ export default (): Plugin => ({
|
|
|
755
754
|
|
|
756
755
|
### `provide`
|
|
757
756
|
|
|
758
|
-
-
|
|
759
|
-
-
|
|
760
|
-
- Hook
|
|
761
|
-
-
|
|
762
|
-
-
|
|
757
|
+
- Function: Modifies the Elements that need to be rendered.
|
|
758
|
+
- Execution Stage: Rendering (SSR/CSR).
|
|
759
|
+
- Hook Model: Pipeline.
|
|
760
|
+
- Type: `Pipeline<{ element: JSX.Element; props: AppProps; context: RuntimeContext }, JSX.Element>`
|
|
761
|
+
- Usage Example:
|
|
763
762
|
|
|
764
763
|
```ts
|
|
765
764
|
import { createContext } from 'react';
|
|
@@ -778,11 +777,12 @@ export default (): Plugin => ({
|
|
|
778
777
|
|
|
779
778
|
### `client`
|
|
780
779
|
|
|
781
|
-
-
|
|
782
|
-
-
|
|
783
|
-
- Hook
|
|
784
|
-
-
|
|
785
|
-
-
|
|
780
|
+
- Function: Customizes the client-side rendering process.
|
|
781
|
+
- Execution Stage: Client-side rendering in the browser.
|
|
782
|
+
- Hook Model: AsyncPipeline.
|
|
783
|
+
- Type: `AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; rootElement: HTMLElement; }, void>`
|
|
784
|
+
- Usage Example:
|
|
785
|
+
|
|
786
786
|
|
|
787
787
|
```ts
|
|
788
788
|
import ReactDOM from 'react-dom';
|
|
@@ -804,11 +804,12 @@ export default (): Plugin => ({
|
|
|
804
804
|
|
|
805
805
|
### `server`
|
|
806
806
|
|
|
807
|
-
-
|
|
808
|
-
-
|
|
809
|
-
- Hook
|
|
810
|
-
-
|
|
811
|
-
-
|
|
807
|
+
- Function: Customize the server-side rendering process.
|
|
808
|
+
- Execution Phase: SSR
|
|
809
|
+
- Hook Model: AsyncPipeline
|
|
810
|
+
- Type: `AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; }, string>`
|
|
811
|
+
- Usage Example:
|
|
812
|
+
|
|
812
813
|
|
|
813
814
|
```ts
|
|
814
815
|
import ReactDomServer from 'react-dom/server';
|