@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.
- package/CHANGELOG.md +16 -0
- package/docs/en/configure/app/experiments/source-build.mdx +13 -0
- package/docs/en/configure/app/source/alias-strategy.mdx +13 -0
- package/docs/en/configure/app/tools/swc.mdx +17 -2
- package/docs/en/guides/advanced-features/rspack-start.mdx +5 -1
- package/docs/en/guides/advanced-features/ssr.mdx +6 -2
- package/docs/en/guides/basic-features/routes.mdx +35 -1
- package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +202 -168
- package/docs/en/tutorials/first-app/c03-css.mdx +3 -2
- package/docs/zh/configure/app/experiments/source-build.mdx +13 -0
- package/docs/zh/configure/app/source/alias-strategy.mdx +13 -0
- package/docs/zh/configure/app/tools/swc.mdx +17 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +5 -1
- package/docs/zh/guides/advanced-features/ssr.mdx +2 -2
- package/docs/zh/guides/basic-features/routes.mdx +42 -4
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +158 -124
- package/package.json +5 -5
@@ -5,15 +5,19 @@ sidebar_position: 8
|
|
5
5
|
|
6
6
|
# Hook 列表
|
7
7
|
|
8
|
-
|
8
|
+
Modern.js 工程体系中包含三类插件:CLI、Runtime、Server,每一类插件可以使用不同的 Hooks。
|
9
9
|
|
10
|
-
|
10
|
+
在本章节中,罗列了所有可用的 Hooks,你可以根据自己的需求来使用对应的 Hook。
|
11
|
+
|
12
|
+
## CLI Common Hooks
|
13
|
+
|
14
|
+
以下是通用的 CLI Hooks,可以在 Modern.js Framework 以及 Modern.js Module 中使用。
|
11
15
|
|
12
16
|
### `beforeConfig`
|
13
17
|
|
14
18
|
- 功能:运行收集配置前的任务
|
15
19
|
- 执行阶段:收集配置前
|
16
|
-
- Hook
|
20
|
+
- Hook 模型:`AsyncWorkflow`
|
17
21
|
- 类型:`AsyncWorkflow<void, void>`
|
18
22
|
- 使用示例:
|
19
23
|
|
@@ -35,7 +39,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
35
39
|
|
36
40
|
- 功能:收集配置
|
37
41
|
- 执行阶段:解析完 `modern.config.ts` 中的配置之后
|
38
|
-
- Hook
|
42
|
+
- Hook 模型:`ParallelWorkflow`
|
39
43
|
- 类型:`ParallelWorkflow<void, unknown>`
|
40
44
|
- 使用示例:
|
41
45
|
|
@@ -55,13 +59,37 @@ export const myPlugin = (): CliPlugin => ({
|
|
55
59
|
});
|
56
60
|
```
|
57
61
|
|
58
|
-
|
62
|
+
如果你需要设置 Modern.js Framework 的配置,请使用 `@modern-js/app-tools` 导出的 `CliPlugin<AppTools>` 类型:
|
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
|
+
插件在 `config` hook 中返回的配置信息,会被 Modern.js 统一收集与合并,最终生成一份 `NormalizedConfig`。在进行配置合并时,优先级由高到低依次为:
|
83
|
+
|
84
|
+
1. 用户在 `modern.config.*` 文件里定义的配置
|
85
|
+
2. 插件通过 `config` hook 定义的配置
|
86
|
+
3. Modern.js 默认配置。
|
59
87
|
|
60
88
|
### `validateSchema`
|
61
89
|
|
62
90
|
- 功能:收集各个插件中配置的用来校验用户配置的 [JSON Schema](https://json-schema.org/)
|
63
|
-
- 执行阶段:`config` Hook
|
64
|
-
- Hook
|
91
|
+
- 执行阶段:`config` Hook 运行完成之后。
|
92
|
+
- Hook 模型:`ParallelWorkflow`
|
65
93
|
- 类型:`ParallelWorkflow<void, unknown>`
|
66
94
|
- 使用示例:
|
67
95
|
|
@@ -116,7 +144,7 @@ export const myPlugin = defineConfig({
|
|
116
144
|
|
117
145
|
就会报错:
|
118
146
|
|
119
|
-
```
|
147
|
+
```
|
120
148
|
$ modern dev
|
121
149
|
1 | {
|
122
150
|
> 2 | "foo": {},
|
@@ -127,7 +155,7 @@ $ modern dev
|
|
127
155
|
|
128
156
|
- 功能:运行主流程的前置准备流程
|
129
157
|
- 执行阶段:校验完配置之后
|
130
|
-
- Hook
|
158
|
+
- Hook 模型:`AsyncWorkflow`
|
131
159
|
- 类型:`AsyncWorkflow<void, void>`
|
132
160
|
- 使用示例:
|
133
161
|
|
@@ -149,7 +177,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
149
177
|
|
150
178
|
- 功能:运行前置准备流程的之后的任务
|
151
179
|
- 执行阶段:前置准备流程之后
|
152
|
-
- Hook
|
180
|
+
- Hook 模型:`AsyncWorkflow`
|
153
181
|
- 类型:`AsyncWorkflow<void, void>`
|
154
182
|
- 使用示例:
|
155
183
|
|
@@ -169,9 +197,9 @@ export const myPlugin = (): CliPlugin => ({
|
|
169
197
|
|
170
198
|
### `commands`
|
171
199
|
|
172
|
-
- 功能:为
|
173
|
-
- 执行阶段:`prepare` Hook
|
174
|
-
- Hook
|
200
|
+
- 功能:为 commander 添加新的 CLI 命令
|
201
|
+
- 执行阶段:`prepare` Hook 运行完成之后
|
202
|
+
- Hook 模型:`AsyncWorkflow`
|
175
203
|
- 类型:`AsyncWorkflow<{ program: Command; }, void>`
|
176
204
|
- 使用示例:
|
177
205
|
|
@@ -213,7 +241,7 @@ foo
|
|
213
241
|
|
214
242
|
- 功能:在退出进程前,重置一些文件状态
|
215
243
|
- 执行阶段:进程退出之前
|
216
|
-
- Hook
|
244
|
+
- Hook 模型:`Workflow`
|
217
245
|
- 类型:`Workflow<void, void>`
|
218
246
|
- 使用示例:
|
219
247
|
|
@@ -235,18 +263,24 @@ export const myPlugin = (): CliPlugin => ({
|
|
235
263
|
由于 Node.js 中退出进程时的回调函数是同步的,所以 `beforeExit` Hook 的类型是 `Workflow`,不能执行异步操作。
|
236
264
|
:::
|
237
265
|
|
266
|
+
## CLI Framework Hooks
|
267
|
+
|
268
|
+
以下是框架的 CLI Hooks,只能在 Modern.js Framework 中使用,不能在 Modern.js Module 中使用。
|
269
|
+
|
270
|
+
你需要从 `@modern-js/app-tools` 中导入 `CliPlugin` 和 `AppTools` 类型,以获得准确的 Hooks 类型提示。
|
271
|
+
|
238
272
|
### `beforeDev`
|
239
273
|
|
240
274
|
- 功能:运行 dev 主流程的之前的任务
|
241
275
|
- 执行阶段:`dev` 命令运行时,项目开始启动前执行
|
242
|
-
- Hook
|
276
|
+
- Hook 模型:`AsyncWorkflow`
|
243
277
|
- 类型:`AsyncWorkflow<void, unknown>`
|
244
278
|
- 使用示例:
|
245
279
|
|
246
280
|
```ts
|
247
|
-
import type { CliPlugin } from '@modern-js/
|
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: () => {
|
@@ -261,14 +295,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
261
295
|
|
262
296
|
- 功能:运行 dev 主流程的之后的任务
|
263
297
|
- 执行阶段:运行 `dev` 命令时,每一次编译完成后执行
|
264
|
-
- Hook
|
298
|
+
- Hook 模型:`AsyncWorkflow`
|
265
299
|
- 类型:`AsyncWorkflow<{ isFirstCompile: boolean }, unknown>`
|
266
300
|
- 使用示例:
|
267
301
|
|
268
302
|
```ts
|
269
|
-
import type { CliPlugin } from '@modern-js/
|
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` 会在每一次编译完成后执行,你可以通过 `isFirstCompile` 参数来判断是否为首次编译:
|
283
317
|
|
284
318
|
```ts
|
285
|
-
import type { CliPlugin } from '@modern-js/
|
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
|
-
### `
|
334
|
+
### `beforeBuild`
|
301
335
|
|
302
|
-
-
|
336
|
+
- 功能:在执行生产环境构建前触发的回调函数,你可以通过 `bundlerConfigs` 参数获取到底层打包工具的最终配置数组。
|
303
337
|
- 如果当前打包工具为 webpack,则获取到的是 webpack 配置数组。
|
304
338
|
- 如果当前打包工具为 Rspack,则获取到的是 Rspack 配置数组。
|
305
339
|
- 配置数组中可能包含一份或多份配置,这取决于你是否开启了 SSR 等功能。
|
306
|
-
-
|
340
|
+
- 执行阶段:运行 `build` 命令后,在开始构建前执行
|
307
341
|
- Hook 模型:`AsyncWorkflow`
|
308
342
|
- 类型:
|
309
343
|
|
310
344
|
```ts
|
311
|
-
type
|
312
|
-
|
313
|
-
|
314
|
-
>;
|
345
|
+
type BeforeBuild = AsyncWorkflow<{
|
346
|
+
bundlerConfigs: WebpackConfig[] | RspackConfig[];
|
347
|
+
}>;
|
315
348
|
```
|
316
349
|
|
317
350
|
- 使用示例:
|
318
351
|
|
319
352
|
```ts
|
320
|
-
import type { CliPlugin } from '@modern-js/
|
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
|
-
|
326
|
-
console.log('Before
|
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
|
-
### `
|
367
|
+
### `afterBuild`
|
335
368
|
|
336
|
-
-
|
337
|
-
- 如果当前打包工具为 webpack,则获取到的是 webpack
|
338
|
-
- 如果当前打包工具为 Rspack,则获取到的是 Rspack
|
339
|
-
-
|
369
|
+
- 功能:在执行生产环境构建后触发的回调函数,你可以通过 `stats` 参数获取到构建结果信息。
|
370
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack Stats。
|
371
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack Stats。
|
372
|
+
- 执行阶段:运行 `build` 命令运行后,在项目构建完成之后执行
|
340
373
|
- Hook 模型:`AsyncWorkflow`
|
341
374
|
- 类型:
|
342
375
|
|
343
376
|
```ts
|
344
|
-
type
|
345
|
-
|
346
|
-
|
347
|
-
>;
|
377
|
+
type AfterBuild = AsyncWorkflow<{
|
378
|
+
stats?: Stats | MultiStats;
|
379
|
+
}>;
|
348
380
|
```
|
349
381
|
|
350
382
|
- 使用示例:
|
351
383
|
|
352
384
|
```ts
|
353
|
-
import type { CliPlugin } from '@modern-js/
|
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
|
-
|
359
|
-
console.log('After
|
360
|
-
console.log(
|
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
|
-
### `
|
399
|
+
### `beforeCreateCompiler`
|
400
|
+
|
401
|
+
- 功能:在创建底层 Compiler 实例前触发的回调函数,并且你可以通过 `bundlerConfigs` 参数获取到底层打包工具的最终配置数组:
|
402
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack 配置数组。
|
403
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack 配置数组。
|
404
|
+
- 配置数组中可能包含一份或多份配置,这取决于你是否开启了 SSR 等功能。
|
405
|
+
- 执行阶段:在执行 dev 或 build 命令时,创建 Compiler 实例之前执行
|
406
|
+
- Hook 模型:`AsyncWorkflow`
|
407
|
+
- 类型:
|
408
|
+
|
409
|
+
```ts
|
410
|
+
type BeforeCreateCompiler = AsyncWorkflow<
|
411
|
+
{ bundlerConfigs: Configuration[] },
|
412
|
+
unknown
|
413
|
+
>;
|
414
|
+
```
|
368
415
|
|
369
|
-
- 功能:在中间件函数中可以拿到即将打印的日志信息,并对其进行修改
|
370
|
-
- 执行阶段:打印日志信息之前执行
|
371
|
-
- Hook 模型:AsyncWaterfall
|
372
|
-
- 类型:`AsyncWaterfall<{ instructions: string }>`
|
373
416
|
- 使用示例:
|
374
417
|
|
375
418
|
```ts
|
376
|
-
import type { CliPlugin } from '@modern-js/
|
419
|
+
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
377
420
|
|
378
|
-
export const myPlugin = (): CliPlugin => ({
|
421
|
+
export const myPlugin = (): CliPlugin<AppTools> => ({
|
379
422
|
setup(api) {
|
380
423
|
return {
|
381
|
-
|
382
|
-
|
383
|
-
|
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
|
-
### `
|
433
|
+
### `afterCreateCompiler`
|
393
434
|
|
394
|
-
-
|
395
|
-
- 如果当前打包工具为 webpack,则获取到的是 webpack
|
396
|
-
- 如果当前打包工具为 Rspack,则获取到的是 Rspack
|
397
|
-
|
398
|
-
- 执行阶段:运行 `build` 命令后,在开始构建前执行
|
435
|
+
- 功能:在创建 Compiler 实例后、执行构建前触发的回调函数,并且你可以通过 `compiler` 参数获取到 Compiler 实例对象:
|
436
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack Compiler 对象。
|
437
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack Compiler 对象。
|
438
|
+
- 执行阶段:创建 Compiler 对象之后执行
|
399
439
|
- Hook 模型:`AsyncWorkflow`
|
400
440
|
- 类型:
|
401
441
|
|
402
442
|
```ts
|
403
|
-
type
|
404
|
-
|
405
|
-
|
443
|
+
type AfterCreateCompiler = AsyncWorkflow<
|
444
|
+
{ compiler: Compiler | MultiCompiler | undefined },
|
445
|
+
unknown
|
446
|
+
>;
|
406
447
|
```
|
407
448
|
|
408
449
|
- 使用示例:
|
409
450
|
|
410
451
|
```ts
|
411
|
-
import type { CliPlugin } from '@modern-js/
|
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
|
-
|
417
|
-
console.log('
|
418
|
-
console.log(
|
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
|
-
### `
|
426
|
-
|
427
|
-
- 功能:在执行生产环境构建后触发的回调函数,你可以通过 `stats` 参数获取到构建结果信息。
|
428
|
-
- 如果当前打包工具为 webpack,则获取到的是 webpack Stats。
|
429
|
-
- 如果当前打包工具为 Rspack,则获取到的是 Rspack Stats。
|
430
|
-
- 执行阶段:运行 `build` 命令运行后,在项目构建完成之后执行
|
431
|
-
- Hook 模型:`AsyncWorkflow`
|
432
|
-
- 类型:
|
433
|
-
|
434
|
-
```ts
|
435
|
-
type AfterBuild = AsyncWorkflow<{
|
436
|
-
stats?: Stats | MultiStats;
|
437
|
-
}>;
|
438
|
-
```
|
466
|
+
### `beforePrintInstructions`
|
439
467
|
|
468
|
+
- 功能:在中间件函数中可以拿到即将打印的日志信息,并对其进行修改
|
469
|
+
- 执行阶段:打印日志信息之前执行
|
470
|
+
- Hook 模型:`AsyncWaterfall`
|
471
|
+
- 类型:`AsyncWaterfall<{ instructions: string }>`
|
440
472
|
- 使用示例:
|
441
473
|
|
442
474
|
```ts
|
443
|
-
import type { CliPlugin } from '@modern-js/
|
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
|
-
|
449
|
-
|
450
|
-
|
480
|
+
beforePrintInstructions: ({ instructions }) => {
|
481
|
+
// do something
|
482
|
+
return {
|
483
|
+
instructions: [...instructions, 'some new message'],
|
484
|
+
};
|
451
485
|
},
|
452
486
|
};
|
453
487
|
},
|
@@ -458,14 +492,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
458
492
|
|
459
493
|
- 功能:用于修改、添加生成入口文件中的 `import` 语句
|
460
494
|
- 执行阶段:生成入口文件之前,[`prepare`](#prepare) 阶段触发
|
461
|
-
- Hook
|
495
|
+
- Hook 模型:`AsyncWaterfall`
|
462
496
|
- 类型:`AsyncWaterfall<{ imports: ImportStatement[]; entrypoint: Entrypoint; }>`
|
463
497
|
- 使用示例:
|
464
498
|
|
465
499
|
```ts
|
466
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -490,14 +524,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
490
524
|
|
491
525
|
- 功能:用于修改生成入口文件中的 `export` 语句
|
492
526
|
- 执行阶段:生成入口文件之前,[`prepare`](#prepare) 阶段触发
|
493
|
-
- Hook
|
527
|
+
- Hook 模型:`AsyncWaterfall`
|
494
528
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; exportStatement: string; }>`
|
495
529
|
- 使用示例:
|
496
530
|
|
497
531
|
```ts
|
498
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -517,14 +551,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
517
551
|
|
518
552
|
- 功能:用于添加、修改生成入口文件中的 [Runtime 插件](#Runtime)
|
519
553
|
- 执行阶段:生成入口文件之前,[`prepare`](#prepare) 阶段触发
|
520
|
-
- Hook
|
554
|
+
- Hook 模型:`AsyncWaterfall`
|
521
555
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; plugins: RuntimePlugin[]; }>`
|
522
556
|
- 使用示例:
|
523
557
|
|
524
558
|
```ts
|
525
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -552,14 +586,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
552
586
|
|
553
587
|
- 功能:用于修改生成入口文件中 `render` 函数
|
554
588
|
- 执行阶段:生成入口文件之前,[`prepare`](#prepare) 阶段触发
|
555
|
-
- Hook
|
589
|
+
- Hook 模型:`AsyncWaterfall`
|
556
590
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
|
557
591
|
- 使用示例:
|
558
592
|
|
559
593
|
```ts
|
560
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -578,14 +612,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
578
612
|
|
579
613
|
- 功能:用于修改生成前端页面路由文件中的内容,内容都是需要可序列化的
|
580
614
|
- 执行阶段:生成前端路由文件之前,[`prepare`](#prepare) 阶段触发
|
581
|
-
- Hook
|
615
|
+
- Hook 模型:`AsyncWaterfall`
|
582
616
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; routes: Route[]; }>`
|
583
617
|
- 使用示例:
|
584
618
|
|
585
619
|
```tsx
|
586
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -612,14 +646,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
612
646
|
|
613
647
|
- 功能:用于修改生成服务器路由中的内容
|
614
648
|
- 执行阶段:生成 Server 路由文件之前,[`prepare`](#prepare) 阶段触发
|
615
|
-
- Hook
|
649
|
+
- Hook 模型:`AsyncWaterfall`
|
616
650
|
- 类型:`AsyncWaterfall<{ routes: ServerRoute[]; }>`
|
617
651
|
- 使用示例:
|
618
652
|
|
619
653
|
```ts
|
620
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -645,14 +679,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
645
679
|
|
646
680
|
- 功能:用于修改包裹入口文件的异步模块,参见 [source.enableAsyncEntry](/configure/app/source/enable-async-entry)
|
647
681
|
- 执行阶段:生成入口文件之前,[`prepare`](#prepare) 阶段触发
|
648
|
-
- Hook
|
682
|
+
- Hook 模型:`AsyncWaterfall`
|
649
683
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; code: string; }>`
|
650
684
|
- 使用示例:
|
651
685
|
|
652
686
|
```ts
|
653
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -671,14 +705,14 @@ export const myPlugin = (): CliPlugin => ({
|
|
671
705
|
|
672
706
|
- 功能:用于定制生成的 HTML 页面模版
|
673
707
|
- 执行阶段:[`prepare`](#prepare) 阶段触发
|
674
|
-
- Hook
|
708
|
+
- Hook 模型:`AsyncWaterfall`
|
675
709
|
- 类型:`AsyncWaterfall<{ entrypoint: Entrypoint; partials: HtmlPartials; }>`
|
676
710
|
- 使用示例:
|
677
711
|
|
678
712
|
```ts
|
679
|
-
import type { CliPlugin } from '@modern-js/
|
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 }) {
|
@@ -708,7 +742,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
708
742
|
|
709
743
|
- 功能:在中间件函数中会拿到 Server 初始化用到的指标测量工具配置 `measureOptions` 和日志工具配置 `loggerOptions`,并返回自定义的指标测量工具 `measure` 和日志工具配置 `logger`
|
710
744
|
- 执行阶段:Server 初始化
|
711
|
-
- Hook
|
745
|
+
- Hook 模型:`AsyncPipeline`
|
712
746
|
- 类型:`AsyncPipeline<ServerInitInput, InitExtension>`
|
713
747
|
- 使用示例:
|
714
748
|
|
@@ -730,7 +764,7 @@ export const myPlugin = (): ServerPlugin => ({
|
|
730
764
|
|
731
765
|
- 功能:设置 Web 路由的处理函数,在中间件函数中可以拿到 Web Server 的前置中间件
|
732
766
|
- 执行阶段:在请求到达的时候
|
733
|
-
- Hook
|
767
|
+
- Hook 模型:`AsyncPipeline`
|
734
768
|
- 类型:`AsyncPipeline<WebServerStartInput, Adapter>`
|
735
769
|
- 使用示例:
|
736
770
|
|
@@ -756,7 +790,7 @@ export const myPlugin = (): ServerPlugin => ({
|
|
756
790
|
|
757
791
|
- 功能:设置 API 路由的处理函数,在中间件函数中可以拿到 API Server 的前置中间件
|
758
792
|
- 执行阶段:请求到达并且 match bff basename 之后执行
|
759
|
-
- Hook
|
793
|
+
- Hook 模型:`AsyncPipeline`
|
760
794
|
- 类型:`AsyncPipeline<APIServerStartInput, Adapter>`
|
761
795
|
- 使用示例:
|
762
796
|
|
@@ -791,7 +825,7 @@ Runtime 插件主要用于开发者修改需要渲染的组件。
|
|
791
825
|
|
792
826
|
- 功能:执行 `App.init`
|
793
827
|
- 执行阶段:渲染(SSR/CSR)
|
794
|
-
- Hook
|
828
|
+
- Hook 模型:`AsyncPipeline`
|
795
829
|
- 类型:`AsyncPipeline<{ context: RuntimeContext; }, unknown>`
|
796
830
|
- 使用示例:
|
797
831
|
|
@@ -814,7 +848,7 @@ export const myPlugin = (): Plugin => ({
|
|
814
848
|
|
815
849
|
- 功能:修改需要渲染的组件
|
816
850
|
- 执行阶段:渲染(SSR/CSR)
|
817
|
-
- Hook
|
851
|
+
- Hook 模型:`Pipeline`
|
818
852
|
- 类型:`Pipeline<{ App: React.ComponentType<any>; }, React.ComponentType<any>>`
|
819
853
|
- 使用示例:
|
820
854
|
|
@@ -852,7 +886,7 @@ export const myPlugin = (): Plugin => ({
|
|
852
886
|
|
853
887
|
- 功能:修改需要渲染的 Element
|
854
888
|
- 执行阶段:渲染(SSR/CSR)
|
855
|
-
- Hook
|
889
|
+
- Hook 模型:`Pipeline`
|
856
890
|
- 类型:`Pipeline<{ element: JSX.Element; props: AppProps; context: RuntimeContext }, JSX.Element>`
|
857
891
|
- 使用示例:
|
858
892
|
|
@@ -875,7 +909,7 @@ export const myPlugin = (): Plugin => ({
|
|
875
909
|
|
876
910
|
- 功能:定制客户端渲染流程
|
877
911
|
- 执行阶段:在浏览器客户端渲染
|
878
|
-
- Hook
|
912
|
+
- Hook 模型:`AsyncPipeline`
|
879
913
|
- 类型:`AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; rootElement: HTMLElement; }, void>`
|
880
914
|
- 使用示例:
|
881
915
|
|
@@ -901,7 +935,7 @@ export const myPlugin = (): Plugin => ({
|
|
901
935
|
|
902
936
|
- 功能:定制服务器端渲染流程
|
903
937
|
- 执行阶段:SSR
|
904
|
-
- Hook
|
938
|
+
- Hook 模型:`AsyncPipeline`
|
905
939
|
- 类型:`AsyncPipeline<{ App: React.ComponentType<any>; context?: RuntimeContext; }, string>`
|
906
940
|
- 使用示例:
|
907
941
|
|
package/package.json
CHANGED
@@ -15,14 +15,14 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.28.0",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
|
-
"@modern-js/builder-doc": "^2.
|
25
|
+
"@modern-js/builder-doc": "^2.28.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"classnames": "^2",
|
@@ -34,9 +34,9 @@
|
|
34
34
|
"fs-extra": "^10",
|
35
35
|
"@types/node": "^16",
|
36
36
|
"@types/fs-extra": "^9",
|
37
|
-
"@modern-js/builder-doc": "2.
|
38
|
-
"@modern-js/doc-
|
39
|
-
"@modern-js/doc-
|
37
|
+
"@modern-js/builder-doc": "2.28.0",
|
38
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.28.0",
|
39
|
+
"@modern-js/doc-tools": "2.28.0"
|
40
40
|
},
|
41
41
|
"scripts": {
|
42
42
|
"dev": "modern dev",
|