@modern-js/main-doc 2.26.0 → 2.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,17 +5,21 @@ sidebar_position: 8
5
5
 
6
6
  # Hook List
7
7
 
8
- Modern.js exposes three types of plugins: CLI, Runtime, and Server.
8
+ In the Modern.js engineering system, there are three types of plugins: CLI, Runtime, and Server. Each type of plugin can utilize different Hooks.
9
9
 
10
- ## CLI
10
+ In this chapter, all available Hooks are listed, and you can use the corresponding Hook based on your needs.
11
+
12
+ ## CLI Common Hooks
13
+
14
+ The following are the common CLI Hooks that can be used in both Modern.js Framework and Modern.js Module.
11
15
 
12
16
  ### `beforeConfig`
13
17
 
14
18
  - Functionality: Running tasks before the config process
15
19
  - Execution phase: Before the config process
16
- - Hook model: AsyncWorkflow
20
+ - Hook model: `AsyncWorkflow`
17
21
  - Type: `AsyncWorkflow<void, void>`
18
- - Example usage:
22
+ - Example:
19
23
 
20
24
  ```ts
21
25
  import type { CliPlugin } from '@modern-js/core';
@@ -35,9 +39,9 @@ export const myPlugin = (): CliPlugin => ({
35
39
 
36
40
  - Functionality: Collect configuration
37
41
  - Execution phase: After parsing the configuration in `modern.config.ts`
38
- - Hook model: ParallelWorkflow
42
+ - Hook model: `ParallelWorkflow`
39
43
  - Type: `ParallelWorkflow<void, unknown>`
40
- - Example usage:
44
+ - Example:
41
45
 
42
46
  ```ts
43
47
  import type { CliPlugin } from '@modern-js/core';
@@ -55,15 +59,39 @@ export const myPlugin = (): CliPlugin => ({
55
59
  });
56
60
  ```
57
61
 
58
- The collected configuration information will be collected and processed uniformly.
62
+ If you need to set the configuration of the Modern.js Framework, please use the `CliPlugin<AppTools>` type exported by `@modern-js/app-tools`:
63
+
64
+ ```ts
65
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
66
+
67
+ export const myPlugin = (): CliPlugin => ({
68
+ setup(api) {
69
+ return {
70
+ config: () => {
71
+ return {
72
+ output: {
73
+ polyfill: 'usage',
74
+ },
75
+ };
76
+ },
77
+ };
78
+ },
79
+ });
80
+ ```
81
+
82
+ The configuration returned by the `config` hook will be collected and merged by Modern.js, resulting in a `NormalizedConfig`. When merging configurations, the priority is as follows, from high to low:
83
+
84
+ 1. Configuration defined by the user in the `modern.config.*` file.
85
+ 2. Configuration defined by the plugin through the `config` hook.
86
+ 3. Default configuration of Modern.js.
59
87
 
60
88
  ### `validateSchema`
61
89
 
62
90
  - Functionality: Collect the JSON schema used to validate user configurations in various plugins.
63
91
  - Execution phase: After the `config` Hook has run.
64
- - Hook model: ParallelWorkflow
92
+ - Hook model: `ParallelWorkflow`
65
93
  - Type: `ParallelWorkflow<void, unknown>`
66
- - Example usage:
94
+ - Example:
67
95
 
68
96
  ```ts
69
97
  import type { CliPlugin } from '@modern-js/core';
@@ -116,7 +144,7 @@ export const myPlugin = defineConfig({
116
144
 
117
145
  then throw error:
118
146
 
119
- ```sh
147
+ ```
120
148
  $ modern dev
121
149
  1 | {
122
150
  > 2 | "foo": {},
@@ -127,9 +155,9 @@ $ modern dev
127
155
 
128
156
  - Functionality: Preparatory process for running the main process.
129
157
  - Execution phase: After configuration validation.
130
- - Hook model: AsyncWorkflow
158
+ - Hook model: `AsyncWorkflow`
131
159
  - Type: `AsyncWorkflow<void, void>`
132
- - Example usage:
160
+ - Example:
133
161
 
134
162
  ```ts
135
163
  import type { CliPlugin } from '@modern-js/core';
@@ -149,7 +177,7 @@ export const myPlugin = (): CliPlugin => ({
149
177
 
150
178
  - function: Running tasks after the prepare process
151
179
  - Execution Phase: After the prepare process
152
- - Hook model: AsyncWorkflow
180
+ - Hook model: `AsyncWorkflow`
153
181
  - type: `AsyncWorkflow<void, void>`
154
182
  - Usage:
155
183
 
@@ -169,11 +197,11 @@ export const myPlugin = (): CliPlugin => ({
169
197
 
170
198
  ### `commands`
171
199
 
172
- - Functionality: Add new commands for the command.
200
+ - Functionality: Add new CLI commands for the commander.
173
201
  - Execution phase: After the `prepare` Hook has run.
174
- - Hook model: AsyncWorkflow
202
+ - Hook model: `AsyncWorkflow`
175
203
  - Type: `AsyncWorkflow<{ program: Command; }, void>`
176
- - Example usage:
204
+ - Example:
177
205
 
178
206
  ```ts
179
207
  import type { CliPlugin } from '@modern-js/core';
@@ -213,9 +241,9 @@ foo
213
241
 
214
242
  - Functionality: Reset some file states before exiting the process.
215
243
  - Execution phase: Before the process exits.
216
- - Hook model: Workflow
244
+ - Hook model: `Workflow`
217
245
  - Type: `Workflow<void, void>`
218
- - Example usage:
246
+ - Example:
219
247
 
220
248
  ```ts
221
249
  import type { CliPlugin } from '@modern-js/core';
@@ -235,18 +263,24 @@ export const myPlugin = (): CliPlugin => ({
235
263
  Since the callback function when exiting the process in Node.js is synchronous, the type of `beforeExit` Hook is `Workflow` and cannot perform asynchronous operations.
236
264
  :::
237
265
 
266
+ ## CLI Framework Hooks
267
+
268
+ The following are the CLI Hooks of the framework, which can only be used in Modern.js Framework and cannot be used in Modern.js Module.
269
+
270
+ You need to import the `CliPlugin` and `AppTools` types from `@modern-js/app-tools` to get accurate type hints for Hooks.
271
+
238
272
  ### `beforeDev`
239
273
 
240
274
  - Functionality: Tasks before running the main dev process.
241
275
  - Execution phase: Before the project starts when the `dev` command is run.
242
- - Hook model: AsyncWorkflow
276
+ - Hook model: `AsyncWorkflow`
243
277
  - Type: `AsyncWorkflow<void, unknown>`
244
- - Example usage:
278
+ - Example:
245
279
 
246
280
  ```ts
247
- import type { CliPlugin } from '@modern-js/core';
281
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
248
282
 
249
- export const myPlugin = (): CliPlugin => ({
283
+ export const myPlugin = (): CliPlugin<AppTools> => ({
250
284
  setup(api) {
251
285
  return {
252
286
  beforeDev: () => {
@@ -260,15 +294,15 @@ export const myPlugin = (): CliPlugin => ({
260
294
  ### `afterDev`
261
295
 
262
296
  - Function: Tasks to be executed after the main process of `dev` command
263
- - Execution Stage: It is executed after each compilation is completed when running the `dev` command
264
- - Hook Model: AsyncWorkflow
297
+ - Execution stage: It is executed after each compilation is completed when running the `dev` command
298
+ - Hook model: `AsyncWorkflow`
265
299
  - Type: `AsyncWorkflow<{ isFirstCompile: boolean }, unknown>`
266
- - Usage Example:
300
+ - Example:
267
301
 
268
302
  ```ts
269
- import type { CliPlugin } from '@modern-js/core';
303
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
270
304
 
271
- export const myPlugin = (): CliPlugin => ({
305
+ export const myPlugin = (): CliPlugin<AppTools> => ({
272
306
  setup(api) {
273
307
  return {
274
308
  afterDev: () => {
@@ -282,9 +316,9 @@ export const myPlugin = (): CliPlugin => ({
282
316
  `afterDev` will be executed after each compilation is completed, you can use the `isFirstCompile` param to determine whether it is the first compilation:
283
317
 
284
318
  ```ts
285
- import type { CliPlugin } from '@modern-js/core';
319
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
286
320
 
287
- export const myPlugin = (): CliPlugin => ({
321
+ export const myPlugin = (): CliPlugin<AppTools> => ({
288
322
  setup(api) {
289
323
  return {
290
324
  afterDev: ({ isFirstCompile }) => {
@@ -297,33 +331,32 @@ export const myPlugin = (): CliPlugin => ({
297
331
  });
298
332
  ```
299
333
 
300
- ### `beforeCreateCompiler`
334
+ ### `beforeBuild`
301
335
 
302
- - Function: A callback function triggered before creating the underlying Compiler instance, and you can get the final configuration array of the underlying bundler through the `bundlerConfigs` parameter:
336
+ - Function: A callback function triggered before executing production environment builds. You can access the final configuration array of the underlying bundler through the `bundlerConfigs` parameter.
303
337
  - If the current bundler is webpack, you will get the webpack Compiler object.
304
338
  - If the current bundler is Rspack, you will get the Rspack Compiler object.
305
339
  - The configuration array may contain one or multiple configurations, depending on whether you have enabled features such as SSR.
306
- - Execution Stage: Executed before creating the Compiler instance when running the `dev` or `build` command.
307
- - Hook Model: `AsyncWorkflow`.
340
+ - Execution stage: Executed after running the `build` command and before the actual build process begins.
341
+ - Hook model: `AsyncWorkflow`.
308
342
  - Type:
309
343
 
310
344
  ```ts
311
- type BeforeCreateCompiler = AsyncWorkflow<
312
- { bundlerConfigs: Configuration[] },
313
- unknown
314
- >;
345
+ type BeforeBuild = AsyncWorkflow<{
346
+ bundlerConfigs: WebpackConfig[] | RspackConfig[];
347
+ }>;
315
348
  ```
316
349
 
317
- - Usage Example:
350
+ - Example:
318
351
 
319
352
  ```ts
320
- import type { CliPlugin } from '@modern-js/core';
353
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
321
354
 
322
- export const myPlugin = (): CliPlugin => ({
355
+ export const myPlugin = (): CliPlugin<AppTools> => ({
323
356
  setup(api) {
324
357
  return {
325
- beforeCreateCompiler: ({ bundlerConfigs }) => {
326
- console.log('Before create compiler.');
358
+ beforeBuild: ({ bundlerConfigs }) => {
359
+ console.log('Before build.');
327
360
  console.log(bundlerConfigs);
328
361
  },
329
362
  };
@@ -331,123 +364,124 @@ export const myPlugin = (): CliPlugin => ({
331
364
  });
332
365
  ```
333
366
 
334
- ### `afterCreateCompiler`
367
+ ### `afterBuild`
335
368
 
336
- - Function: A callback function triggered after creating a Compiler instance and before executing the build. You can access the Compiler instance object through the `compiler` parameter:
337
- - If the current bundler is webpack, you will get the webpack Compiler object.
338
- - If the current bundler is Rspack, you will get the Rspack Compiler object.
339
- - Execution Stage: Executed after creating the Compiler object.
340
- - Hook Model: `AsyncWorkflow`.
369
+ - Function: A callback function triggered after running the production build. You can access the build result information through the `stats` parameter.
370
+ - If the current bundler is webpack, you will get webpack Stats.
371
+ - If the current bundler is Rspack, you will get Rspack Stats.
372
+ - Execution stage: It is executed after running the `build` command and completing the build.
373
+ - Hook model: `AsyncWorkflow`.
341
374
  - Type:
342
375
 
343
376
  ```ts
344
- type AfterCreateCompiler = AsyncWorkflow<
345
- { compiler: Compiler | MultiCompiler | undefined },
346
- unknown
347
- >;
377
+ type AfterBuild = AsyncWorkflow<{
378
+ stats?: Stats | MultiStats;
379
+ }>;
348
380
  ```
349
381
 
350
- - Usage Example:
382
+ - Example:
351
383
 
352
384
  ```ts
353
- import type { CliPlugin } from '@modern-js/core';
385
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
354
386
 
355
- export const myPlugin = (): CliPlugin => ({
387
+ export const myPlugin = (): CliPlugin<AppTools> => ({
356
388
  setup(api) {
357
389
  return {
358
- afterCreateCompiler: ({ compiler }) => {
359
- console.log('After create compiler.');
360
- console.log(compiler);
390
+ afterBuild: ({ stats }) => {
391
+ console.log('After build.');
392
+ console.log(stats);
361
393
  },
362
394
  };
363
395
  },
364
396
  });
365
397
  ```
366
398
 
367
- ### `beforePrintInstructions`
399
+ ### `beforeCreateCompiler`
368
400
 
369
- - Function: Provides access to the log information that will be printed within middleware functions and allows modification of the log information.
370
- - Execution Stage: Executed before printing the log information.
371
- - Hook Model: AsyncWaterfall.
372
- - Type: `AsyncWaterfall<{ instructions: string }>`
373
- - Usage Example:
401
+ - Function: A callback function triggered before creating the underlying Compiler instance, and you can get the final configuration array of the underlying bundler through the `bundlerConfigs` parameter:
402
+ - If the current bundler is webpack, you will get the webpack Compiler object.
403
+ - If the current bundler is Rspack, you will get the Rspack Compiler object.
404
+ - The configuration array may contain one or multiple configurations, depending on whether you have enabled features such as SSR.
405
+ - Execution stage: Executed before creating the Compiler instance when running the `dev` or `build` command.
406
+ - Hook model: `AsyncWorkflow`.
407
+ - Type:
374
408
 
375
409
  ```ts
376
- import type { CliPlugin } from '@modern-js/core';
410
+ type BeforeCreateCompiler = AsyncWorkflow<
411
+ { bundlerConfigs: Configuration[] },
412
+ unknown
413
+ >;
414
+ ```
377
415
 
378
- export const myPlugin = (): CliPlugin => ({
416
+ - Example:
417
+
418
+ ```ts
419
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
420
+
421
+ export const myPlugin = (): CliPlugin<AppTools> => ({
379
422
  setup(api) {
380
423
  return {
381
- beforePrintInstructions: ({ instructions }) => {
382
- // do something
383
- return {
384
- instructions: [...instructions, 'some new message'],
385
- };
424
+ beforeCreateCompiler: ({ bundlerConfigs }) => {
425
+ console.log('Before create compiler.');
426
+ console.log(bundlerConfigs);
386
427
  },
387
428
  };
388
429
  },
389
430
  });
390
431
  ```
391
432
 
392
- ### `beforeBuild`
433
+ ### `afterCreateCompiler`
393
434
 
394
- - Function: A callback function triggered before executing production environment builds. You can access the final configuration array of the underlying bundler through the `bundlerConfigs` parameter.
435
+ - Function: A callback function triggered after creating a Compiler instance and before executing the build. You can access the Compiler instance object through the `compiler` parameter:
395
436
  - If the current bundler is webpack, you will get the webpack Compiler object.
396
437
  - If the current bundler is Rspack, you will get the Rspack Compiler object.
397
- - The configuration array may contain one or multiple configurations, depending on whether you have enabled features such as SSR.
398
- - Execution Stage: Executed after running the `build` command and before the actual build process begins.
399
- - Hook Model: `AsyncWorkflow`.
438
+ - Execution stage: Executed after creating the Compiler object.
439
+ - Hook model: `AsyncWorkflow`.
400
440
  - Type:
401
441
 
402
442
  ```ts
403
- type BeforeBuild = AsyncWorkflow<{
404
- bundlerConfigs: WebpackConfig[] | RspackConfig[];
405
- }>;
443
+ type AfterCreateCompiler = AsyncWorkflow<
444
+ { compiler: Compiler | MultiCompiler | undefined },
445
+ unknown
446
+ >;
406
447
  ```
407
448
 
408
- - Usage Example:
449
+ - Example:
409
450
 
410
451
  ```ts
411
- import type { CliPlugin } from '@modern-js/core';
452
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
412
453
 
413
- export const myPlugin = (): CliPlugin => ({
454
+ export const myPlugin = (): CliPlugin<AppTools> => ({
414
455
  setup(api) {
415
456
  return {
416
- beforeBuild: ({ bundlerConfigs }) => {
417
- console.log('Before build.');
418
- console.log(bundlerConfigs);
457
+ afterCreateCompiler: ({ compiler }) => {
458
+ console.log('After create compiler.');
459
+ console.log(compiler);
419
460
  },
420
461
  };
421
462
  },
422
463
  });
423
464
  ```
424
465
 
425
- ### `afterBuild`
426
-
427
- - Function: A callback function triggered after running the production build. You can access the build result information through the `stats` parameter.
428
- - If the current bundler is webpack, you will get webpack Stats.
429
- - If the current bundler is Rspack, you will get Rspack Stats.
430
- - Execution Stage: It is executed after running the `build` command and completing the build.
431
- - Hook Model: `AsyncWorkflow`.
432
- - Type:
433
-
434
- ```ts
435
- type AfterBuild = AsyncWorkflow<{
436
- stats?: Stats | MultiStats;
437
- }>;
438
- ```
466
+ ### `beforePrintInstructions`
439
467
 
440
- - Usage Example:
468
+ - Function: Provides access to the log information that will be printed within middleware functions and allows modification of the log information.
469
+ - Execution stage: Executed before printing the log information.
470
+ - Hook model: `AsyncWaterfall`
471
+ - Type: `AsyncWaterfall<{ instructions: string }>`
472
+ - Example:
441
473
 
442
474
  ```ts
443
- import type { CliPlugin } from '@modern-js/core';
475
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
444
476
 
445
- export const myPlugin = (): CliPlugin => ({
477
+ export const myPlugin = (): CliPlugin<AppTools> => ({
446
478
  setup(api) {
447
479
  return {
448
- afterBuild: ({ stats }) => {
449
- console.log('After build.');
450
- console.log(stats);
480
+ beforePrintInstructions: ({ instructions }) => {
481
+ // do something
482
+ return {
483
+ instructions: [...instructions, 'some new message'],
484
+ };
451
485
  },
452
486
  };
453
487
  },
@@ -457,15 +491,15 @@ export const myPlugin = (): CliPlugin => ({
457
491
  ### `modifyEntryImports`
458
492
 
459
493
  - Function: Used for modifying or adding `import` statements in the generated entry files.
460
- - Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
461
- - Hook Model: AsyncWaterfall.
494
+ - Execution stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
495
+ - Hook model: `AsyncWaterfall`
462
496
  - Type: `AsyncWaterfall<{ imports: ImportStatement[]; entrypoint: Entrypoint; }>`
463
- - Usage Example:
497
+ - Example:
464
498
 
465
499
  ```ts
466
- import type { CliPlugin } from '@modern-js/core';
500
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
467
501
 
468
- export const myPlugin = (): CliPlugin => ({
502
+ export const myPlugin = (): CliPlugin<AppTools> => ({
469
503
  setup(api) {
470
504
  return {
471
505
  modifyEntryImports({ entrypoint, imports }) {
@@ -489,15 +523,15 @@ export const myPlugin = (): CliPlugin => ({
489
523
  ### `modifyEntryExport`
490
524
 
491
525
  - Function: used to modify the `export` statement in the generated entry file
492
- - Execution Stage: Before the entry file is generated, the [`prepare`](#prepare) phase triggers
493
- - Hook Model: AsyncWaterfall
526
+ - Execution stage: Before the entry file is generated, the [`prepare`](#prepare) phase triggers
527
+ - Hook model: `AsyncWaterfall`
494
528
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; exportStatement: string; }>`
495
- - Example of use:
529
+ - Example:
496
530
 
497
531
  ```ts
498
- import type { CliPlugin } from '@modern-js/core';
532
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
499
533
 
500
- export const myPlugin = (): CliPlugin => ({
534
+ export const myPlugin = (): CliPlugin<AppTools> => ({
501
535
  setup(api) {
502
536
  return {
503
537
  modifyEntryExport({ entrypoint, exportStatement }) {
@@ -516,15 +550,15 @@ export const myPlugin = (): CliPlugin => ({
516
550
  ### `modifyEntryRuntimePlugins`
517
551
 
518
552
  - Function: Used for adding or modifying [Runtime plugins](#Runtime) in the generated entry files.
519
- - Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
520
- - Hook Model: AsyncWaterfall.
553
+ - Execution stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
554
+ - Hook model: `AsyncWaterfall`
521
555
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; plugins: RuntimePlugin[]; }>`
522
- - Usage Example:
556
+ - Example:
523
557
 
524
558
  ```ts
525
- import type { CliPlugin } from '@modern-js/core';
559
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
526
560
 
527
- export const myPlugin = (): CliPlugin => ({
561
+ export const myPlugin = (): CliPlugin<AppTools> => ({
528
562
  setup(api) {
529
563
  return {
530
564
  modifyEntryRuntimePlugins({ entrypoint, plugins }) {
@@ -551,15 +585,15 @@ export const myPlugin = (): CliPlugin => ({
551
585
  ### `modifyEntryRenderFunction`
552
586
 
553
587
  - Function: Used for modifying the `render` function in the generated entry files.
554
- - Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
555
- - Hook Model: AsyncWaterfall.
588
+ - Execution stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
589
+ - Hook model: `AsyncWaterfall`
556
590
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
557
- - Usage Example:
591
+ - Example:
558
592
 
559
593
  ```ts
560
- import type { CliPlugin } from '@modern-js/core';
594
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
561
595
 
562
- export const myPlugin = (): CliPlugin => ({
596
+ export const myPlugin = (): CliPlugin<AppTools> => ({
563
597
  setup(api) {
564
598
  return {
565
599
  modifyEntryRenderFunction({ entrypoint, code }) {
@@ -577,15 +611,15 @@ export const myPlugin = (): CliPlugin => ({
577
611
  ### `modifyFileSystemRoutes`
578
612
 
579
613
  - Function: Used for modifying the content of the generated front-end page routing files, which must be serializable.
580
- - Execution Stage: Executed before generating the front-end routing files, triggered during the [`prepare`](#prepare) stage.
581
- - Hook Model: AsyncWaterfall.
614
+ - Execution stage: Executed before generating the front-end routing files, triggered during the [`prepare`](#prepare) stage.
615
+ - Hook model: `AsyncWaterfall`
582
616
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; routes: Route[]; }>`
583
- - Usage Example:
617
+ - Example:
584
618
 
585
619
  ```tsx
586
- import type { CliPlugin } from '@modern-js/core';
620
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
587
621
 
588
- export const myPlugin = (): CliPlugin => ({
622
+ export const myPlugin = (): CliPlugin<AppTools> => ({
589
623
  setup(api) {
590
624
  return {
591
625
  modifyFileSystemRoutes({ entrypoint, routes }) {
@@ -611,15 +645,15 @@ This adds a new page route for the front-end.
611
645
  ### `modifyServerRoutes`
612
646
 
613
647
  - Function: Used for modifying the content of the generated server routes.
614
- - Execution Stage: Executed before generating the server routing files, triggered during the [`prepare`](#prepare) stage.
615
- - Hook Model: AsyncWaterfall.
648
+ - Execution stage: Executed before generating the server routing files, triggered during the [`prepare`](#prepare) stage.
649
+ - Hook model: `AsyncWaterfall`
616
650
  - Type: `AsyncWaterfall<{ routes: ServerRoute[]; }>`
617
- - Usage Example:
651
+ - Example:
618
652
 
619
653
  ```ts
620
- import type { CliPlugin } from '@modern-js/core';
654
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
621
655
 
622
- export const myPlugin = (): CliPlugin => ({
656
+ export const myPlugin = (): CliPlugin<AppTools> => ({
623
657
  setup(api) {
624
658
  return {
625
659
  modifyServerRoutes({ routes }) {
@@ -644,15 +678,15 @@ export const myPlugin = (): CliPlugin => ({
644
678
  ### `modifyAsyncEntry`
645
679
 
646
680
  - Function: Used for modifying the asynchronous module that wraps the entry file, see [source.enableAsyncEntry](/configure/app/source/enable-async-entry).
647
- - Execution Stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
648
- - Hook Model: AsyncWaterfall.
681
+ - Execution stage: Executed before generating the entry files, triggered during the [`prepare`](#prepare) stage.
682
+ - Hook model: `AsyncWaterfall`
649
683
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
650
- - Usage Example:
684
+ - Example:
651
685
 
652
686
  ```ts
653
- import type { CliPlugin } from '@modern-js/core';
687
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
654
688
 
655
- export const myPlugin = (): CliPlugin => ({
689
+ export const myPlugin = (): CliPlugin<AppTools> => ({
656
690
  setup(api) {
657
691
  return {
658
692
  modifyAsyncEntry({ entrypoint, code }) {
@@ -670,15 +704,15 @@ export const myPlugin = (): CliPlugin => ({
670
704
  ### `htmlPartials`
671
705
 
672
706
  - Function: Used for customizing the generated HTML page template.
673
- - Execution Stage: Triggered during the [`prepare`](#prepare) stage.
674
- - Hook Model: AsyncWaterfall.
707
+ - Execution stage: Triggered during the [`prepare`](#prepare) stage.
708
+ - Hook model: `AsyncWaterfall`
675
709
  - Type: `AsyncWaterfall<{ entrypoint: Entrypoint; partials: HtmlPartials; }>`
676
- - Usage Example:
710
+ - Example:
677
711
 
678
712
  ```ts
679
- import type { CliPlugin } from '@modern-js/core';
713
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
680
714
 
681
- export const myPlugin = (): CliPlugin => ({
715
+ export const myPlugin = (): CliPlugin<AppTools> => ({
682
716
  setup(api) {
683
717
  return {
684
718
  async htmlPartials({ entrypoint, partials }) {
@@ -706,10 +740,10 @@ Plugins are also supported in the Server section of the application project. The
706
740
  ### `create`
707
741
 
708
742
  - 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`.
709
- - Execution Stage: Server initialization.
710
- - Hook Model: AsyncPipeline.
743
+ - Execution stage: Server initialization.
744
+ - Hook model: `AsyncPipeline`
711
745
  - Type: `AsyncPipeline<ServerInitInput, InitExtension>`
712
- - Usage Example:
746
+ - Example:
713
747
 
714
748
  ```ts
715
749
  import type { ServerPlugin } from '@modern-js/server-core';
@@ -728,10 +762,10 @@ export const myPlugin = (): ServerPlugin => ({
728
762
  ### `prepareWebServer`
729
763
 
730
764
  - Function: Sets the handling function for the Web route. In the middleware function, you can get the front-end middleware of the Web server.
731
- - Execution Stage: When the request arrives.
732
- - Hook Model: AsyncPipeline.
765
+ - Execution stage: When the request arrives.
766
+ - Hook model: `AsyncPipeline`
733
767
  - Type: `AsyncPipeline<WebServerStartInput, Adapter>`
734
- - Usage Example:
768
+ - Example:
735
769
 
736
770
  ```ts
737
771
  import type { ServerPlugin } from '@modern-js/server-core';
@@ -754,10 +788,10 @@ export const myPlugin = (): ServerPlugin => ({
754
788
  ### `prepareApiServer`
755
789
 
756
790
  - Function: Sets the handling function for the API route. In the middleware function, you can get the front-end middleware of the API server.
757
- - Execution Stage: When the request arrives and matches the BFF basename.
758
- - Hook Model: AsyncPipeline.
791
+ - Execution stage: When the request arrives and matches the BFF basename.
792
+ - Hook model: `AsyncPipeline`
759
793
  - Type: `AsyncPipeline<APIServerStartInput, Adapter>`
760
- - Usage Example:
794
+ - Example:
761
795
 
762
796
  ```ts
763
797
  import type { ServerPlugin } from '@modern-js/server-core';
@@ -788,10 +822,10 @@ The Runtime plugin is mainly used for developers to modify the component that ne
788
822
  ### `init`
789
823
 
790
824
  - Function: Executes `App.init`.
791
- - Execution Stage: Rendering (SSR/CSR).
792
- - Hook Model: AsyncPipeline.
825
+ - Execution stage: Rendering (SSR/CSR).
826
+ - Hook model: `AsyncPipeline`
793
827
  - Type: `AsyncPipeline<{ context: RuntimeContext; }, unknown>`
794
- - Usage Example:
828
+ - Example:
795
829
 
796
830
  ```ts
797
831
  import type { Plugin } from '@modern-js/runtime';
@@ -811,10 +845,10 @@ export const myPlugin = (): Plugin => ({
811
845
  ### `hoc`
812
846
 
813
847
  - Function: Modifies the components that need to be rendered.
814
- - Execution Stage: Rendering (SSR/CSR).
815
- - Hook Model: Pipeline.
848
+ - Execution stage: Rendering (SSR/CSR).
849
+ - Hook model: `Pipeline`
816
850
  - Type: `Pipeline<{ App: React.ComponentType<any>; }, React.ComponentType<any>>`
817
- - Usage Example:
851
+ - Example:
818
852
 
819
853
  :::note
820
854
  When using the hoc hook, you need to copy the static properties of the original App component to the new component and pass through the props.
@@ -849,10 +883,10 @@ export const myPlugin = (): Plugin => ({
849
883
  {/* ### `provide`
850
884
 
851
885
  - Function: Modifies the Elements that need to be rendered.
852
- - Execution Stage: Rendering (SSR/CSR).
853
- - Hook Model: Pipeline.
886
+ - Execution stage: Rendering (SSR/CSR).
887
+ - Hook model: `Pipeline`
854
888
  - Type: `Pipeline<{ element: JSX.Element; props: AppProps; context: RuntimeContext }, JSX.Element>`
855
- - Usage Example:
889
+ - Example:
856
890
 
857
891
  ```ts
858
892
  import { createContext } from 'react';
@@ -872,10 +906,10 @@ export const myPlugin = (): Plugin => ({
872
906
  ### `client`
873
907
 
874
908
  - Function: Customizes the client-side rendering process.
875
- - Execution Stage: Client-side rendering in the browser.
876
- - Hook Model: AsyncPipeline.
909
+ - Execution stage: Client-side rendering in the browser.
910
+ - Hook model: `AsyncPipeline`
877
911
  - Type: `AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; rootElement: HTMLElement; }, void>`
878
- - Usage Example:
912
+ - Example:
879
913
 
880
914
  ```ts
881
915
  import ReactDOM from 'react-dom';
@@ -899,9 +933,9 @@ export const myPlugin = (): Plugin => ({
899
933
 
900
934
  - Function: Customize the server-side rendering process.
901
935
  - Execution Phase: SSR
902
- - Hook Model: AsyncPipeline
936
+ - Hook model: `AsyncPipeline`
903
937
  - Type: `AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; }, string>`
904
- - Usage Example:
938
+ - Example:
905
939
 
906
940
  ```ts
907
941
  import ReactDomServer from 'react-dom/server';