@modern-js/main-doc 2.25.2 → 2.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +6 -5
- package/docs/en/configure/app/tools/swc.mdx +2 -0
- package/docs/en/guides/get-started/quick-start.mdx +23 -3
- package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +67 -23
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +1 -1
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/configure/app/deploy/microFrontend.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -5
- package/docs/zh/configure/app/tools/swc.mdx +2 -0
- package/docs/zh/guides/advanced-features/using-storybook.mdx +1 -1
- package/docs/zh/guides/get-started/quick-start.mdx +28 -7
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +67 -23
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
@@ -32,14 +32,15 @@ When the value type is `Object`, the following properties can be configured:
|
|
32
32
|
```ts title="modern.config.ts"
|
33
33
|
export default defineConfig({
|
34
34
|
server: {
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
ssr: {
|
36
|
+
forceCSR: true,
|
37
|
+
mode: 'stream',
|
38
|
+
inlineScript: false,
|
39
|
+
},
|
38
40
|
},
|
39
41
|
});
|
40
42
|
```
|
41
43
|
|
42
|
-
|
43
44
|
### Active Fallback
|
44
45
|
|
45
46
|
In a production environment, there are scenarios where it is necessary to actively fallback an SSR project to CSR. Examples include
|
@@ -50,7 +51,7 @@ In a production environment, there are scenarios where it is necessary to active
|
|
50
51
|
|
51
52
|
3. When the SSR server is under heavy load, it may be necessary to fallback some traffic directly to the CSR to avoid service downtime.
|
52
53
|
|
53
|
-
By configuring `ssr.
|
54
|
+
By configuring `server.ssr.forceCSR` to `true` in the project, you can control this behavior through query strings or request headers.
|
54
55
|
|
55
56
|
For example, in a custom Web Server middleware, you can actively fallback when traffic exceeds a certain threshold:
|
56
57
|
|
@@ -15,6 +15,8 @@ import SWC from '@modern-js/builder-doc/docs/en/shared/swc.md';
|
|
15
15
|
|
16
16
|
:::tip
|
17
17
|
When using Rspack as the bundler, SWC will be used for transpiling and compression by default, so you don't need to install or configure the SWC plugin.
|
18
|
+
|
19
|
+
If you have configured the current SWC plugin when using Rspack, it will not have any effect.
|
18
20
|
:::
|
19
21
|
|
20
22
|
## Install
|
@@ -13,7 +13,7 @@ import Prerequisites from "@site-docs-en/components/prerequisites"
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
|
-
Modern.js provides the `@modern-js/create` tool to create projects.
|
16
|
+
Modern.js provides the `@modern-js/create` tool to create projects. It does not require global installation and can be run on-demand using `npx`.
|
17
17
|
|
18
18
|
You can create a project in an existing empty directory:
|
19
19
|
|
@@ -47,21 +47,41 @@ In a Modern.js project created using `@modern-js/create`, a `modern.config.ts` f
|
|
47
47
|
You can modify the configuration through this file to override the default behavior of Modern.js. For example, to enable SSR, add the following configuration:
|
48
48
|
|
49
49
|
```ts
|
50
|
-
import { defineConfig } from '@modern-js/app-tools';
|
50
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
51
51
|
|
52
52
|
export default defineConfig({
|
53
53
|
runtime: {
|
54
54
|
router: true,
|
55
|
-
state: true,
|
56
55
|
},
|
57
56
|
server: {
|
58
57
|
ssr: true,
|
59
58
|
},
|
59
|
+
plugins: [appTools()],
|
60
60
|
});
|
61
61
|
```
|
62
62
|
|
63
63
|
After running `pnpm run dev` again, you can find that the project has completed page rendering on the server in the browser's Network menu.
|
64
64
|
|
65
|
+
## Core npm Package
|
66
|
+
|
67
|
+
In a newly created project, the `@modern-js/app-tools` npm package is installed by default. It is the core package of the Modern.js framework and provides the following capabilities:
|
68
|
+
|
69
|
+
- It offers commonly used CLI commands such as `modern dev`, `modern build`, and more.
|
70
|
+
- It integrates Modern.js Core, providing capabilities for configuration parsing, plugin loading, and more.
|
71
|
+
- It integrates Modern.js Builder, providing build capabilities.
|
72
|
+
- It integrates Modern.js Server, providing capabilities for development and production servers.
|
73
|
+
- It integrates some commonly used plugins, such as `plugin-lint`, `plugin-data-loader`, and more.
|
74
|
+
|
75
|
+
`@modern-js/app-tools` is implemented based on the plugin system of Modern.js. Essentially, it is a plugin. Therefore, you need to register `appTools` in the `plugins` field of the configuration file:
|
76
|
+
|
77
|
+
```ts title="modern.config.ts"
|
78
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
79
|
+
|
80
|
+
export default defineConfig({
|
81
|
+
plugins: [appTools()],
|
82
|
+
});
|
83
|
+
```
|
84
|
+
|
65
85
|
## Build the project
|
66
86
|
|
67
87
|
To build the production artifacts of the project, run `pnpm run build` in the project:
|
@@ -299,10 +299,21 @@ export const myPlugin = (): CliPlugin => ({
|
|
299
299
|
|
300
300
|
### `beforeCreateCompiler`
|
301
301
|
|
302
|
-
- Function:
|
303
|
-
-
|
304
|
-
-
|
305
|
-
-
|
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:
|
303
|
+
- If the current bundler is webpack, you will get the webpack Compiler object.
|
304
|
+
- If the current bundler is Rspack, you will get the Rspack Compiler object.
|
305
|
+
- 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`.
|
308
|
+
- Type:
|
309
|
+
|
310
|
+
```ts
|
311
|
+
type BeforeCreateCompiler = AsyncWorkflow<
|
312
|
+
{ bundlerConfigs: Configuration[] },
|
313
|
+
unknown
|
314
|
+
>;
|
315
|
+
```
|
316
|
+
|
306
317
|
- Usage Example:
|
307
318
|
|
308
319
|
```ts
|
@@ -311,8 +322,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
311
322
|
export const myPlugin = (): CliPlugin => ({
|
312
323
|
setup(api) {
|
313
324
|
return {
|
314
|
-
beforeCreateCompiler: ({
|
315
|
-
|
325
|
+
beforeCreateCompiler: ({ bundlerConfigs }) => {
|
326
|
+
console.log('Before create compiler.');
|
327
|
+
console.log(bundlerConfigs);
|
316
328
|
},
|
317
329
|
};
|
318
330
|
},
|
@@ -321,10 +333,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
321
333
|
|
322
334
|
### `afterCreateCompiler`
|
323
335
|
|
324
|
-
- Function:
|
325
|
-
-
|
326
|
-
-
|
327
|
-
-
|
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`.
|
341
|
+
- Type:
|
342
|
+
|
343
|
+
```ts
|
344
|
+
type AfterCreateCompiler = AsyncWorkflow<
|
345
|
+
{ compiler: Compiler | MultiCompiler | undefined },
|
346
|
+
unknown
|
347
|
+
>;
|
348
|
+
```
|
349
|
+
|
328
350
|
- Usage Example:
|
329
351
|
|
330
352
|
```ts
|
@@ -334,7 +356,8 @@ export const myPlugin = (): CliPlugin => ({
|
|
334
356
|
setup(api) {
|
335
357
|
return {
|
336
358
|
afterCreateCompiler: ({ compiler }) => {
|
337
|
-
|
359
|
+
console.log('After create compiler.');
|
360
|
+
console.log(compiler);
|
338
361
|
},
|
339
362
|
};
|
340
363
|
},
|
@@ -368,10 +391,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
368
391
|
|
369
392
|
### `beforeBuild`
|
370
393
|
|
371
|
-
- Function:
|
372
|
-
-
|
373
|
-
-
|
374
|
-
-
|
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.
|
395
|
+
- If the current bundler is webpack, you will get the webpack Compiler object.
|
396
|
+
- 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`.
|
400
|
+
- Type:
|
401
|
+
|
402
|
+
```ts
|
403
|
+
type BeforeBuild = AsyncWorkflow<{
|
404
|
+
bundlerConfigs: WebpackConfig[] | RspackConfig[];
|
405
|
+
}>;
|
406
|
+
```
|
407
|
+
|
375
408
|
- Usage Example:
|
376
409
|
|
377
410
|
```ts
|
@@ -380,8 +413,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
380
413
|
export const myPlugin = (): CliPlugin => ({
|
381
414
|
setup(api) {
|
382
415
|
return {
|
383
|
-
beforeBuild: () => {
|
384
|
-
|
416
|
+
beforeBuild: ({ bundlerConfigs }) => {
|
417
|
+
console.log('Before build.');
|
418
|
+
console.log(bundlerConfigs);
|
385
419
|
},
|
386
420
|
};
|
387
421
|
},
|
@@ -390,10 +424,19 @@ export const myPlugin = (): CliPlugin => ({
|
|
390
424
|
|
391
425
|
### `afterBuild`
|
392
426
|
|
393
|
-
- Function:
|
394
|
-
-
|
395
|
-
-
|
396
|
-
-
|
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
|
+
```
|
439
|
+
|
397
440
|
- Usage Example:
|
398
441
|
|
399
442
|
```ts
|
@@ -402,8 +445,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
402
445
|
export const myPlugin = (): CliPlugin => ({
|
403
446
|
setup(api) {
|
404
447
|
return {
|
405
|
-
afterBuild: () => {
|
406
|
-
|
448
|
+
afterBuild: ({ stats }) => {
|
449
|
+
console.log('After build.');
|
450
|
+
console.log(stats);
|
407
451
|
},
|
408
452
|
};
|
409
453
|
},
|
@@ -215,7 +215,7 @@ Parameter types:
|
|
215
215
|
updateInfo: Record<string, any>
|
216
216
|
```
|
217
217
|
|
218
|
-
- `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `
|
218
|
+
- `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `modernConfig` field. Only the configuration fields under `modernConfig` need to be filled in `updateInfo`.
|
219
219
|
|
220
220
|
For example, enable SSR:
|
221
221
|
|
@@ -52,4 +52,4 @@ export default defineConfig({
|
|
52
52
|
|
53
53
|
- **默认值:** `false`
|
54
54
|
|
55
|
-
是否 `external` 基础库,当设置为 `true` 时,当前子应用将会 `external`:`react`、`react-dom`,`
|
55
|
+
是否 `external` 基础库,当设置为 `true` 时,当前子应用将会 `external`:`react`、`react-dom`,`Modern.js` 主应用会自动 `setExternal` 这两个基础库,如果其他类型的框架请通过 `Garfish.setExternal` 增加 `react`、`react-dom` 依赖
|
@@ -29,13 +29,14 @@ export default defineConfig({
|
|
29
29
|
- `forceCSR`:`boolean = false`,默认关闭强制 CSR 渲染。配置为 `true` 后,在页面访问时添加 `?csr=true` 或添加请求头 `x-modern-ssr-fallback` 即可强制 CSR。
|
30
30
|
- `inlineScript`:`boolean = true`,默认情况下,SSR 的数据会以内联脚本的方式注入到 HTML 中,并且直接赋值给全局变量。配置为 `false` 后,会下发 JSON,而不是赋值给全局变量。
|
31
31
|
|
32
|
-
|
33
32
|
```ts title="modern.config.ts"
|
34
33
|
export default defineConfig({
|
35
34
|
server: {
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
ssr: {
|
36
|
+
forceCSR: true,
|
37
|
+
mode: 'stream',
|
38
|
+
inlineScript: false,
|
39
|
+
},
|
39
40
|
},
|
40
41
|
});
|
41
42
|
```
|
@@ -50,7 +51,7 @@ export default defineConfig({
|
|
50
51
|
|
51
52
|
3. SSR 服务压力过大,需要部分流量直接降级为 CSR,避免服务宕机。
|
52
53
|
|
53
|
-
在项目中配置 `ssr.
|
54
|
+
在项目中配置 `server.ssr.forceCSR` 为 `true` 后,我们可以通过请求的查询字符串,或是请求头来控制这一行为。
|
54
55
|
|
55
56
|
例如在自定义 Web Server 的中间件中,检测到流量大于某一阈值时,主动降级:
|
56
57
|
|
@@ -2,19 +2,20 @@
|
|
2
2
|
title: 快速上手
|
3
3
|
sidebar_position: 2
|
4
4
|
---
|
5
|
+
|
5
6
|
# 快速上手
|
6
7
|
|
7
8
|
## 环境准备
|
8
9
|
|
9
|
-
import Prerequisites from
|
10
|
+
import Prerequisites from '@site-docs/components/prerequisites';
|
10
11
|
|
11
12
|
<Prerequisites />
|
12
13
|
|
13
14
|
## 安装
|
14
15
|
|
15
|
-
Modern.js 提供了 `@modern-js/create`
|
16
|
+
Modern.js 提供了 `@modern-js/create` 工具来创建项目,不需要全局安装,直接使用 `npx` 按需运行即可。
|
16
17
|
|
17
|
-
|
18
|
+
你可以在已有的空目录来创建项目:
|
18
19
|
|
19
20
|
```bash
|
20
21
|
mkdir myapp && cd myapp
|
@@ -29,13 +30,13 @@ npx @modern-js/create@latest myapp
|
|
29
30
|
|
30
31
|
## 初始化项目
|
31
32
|
|
32
|
-
import InitApp from
|
33
|
+
import InitApp from '@site-docs/components/init-app';
|
33
34
|
|
34
35
|
<InitApp />
|
35
36
|
|
36
37
|
## 启动项目
|
37
38
|
|
38
|
-
import DebugApp from
|
39
|
+
import DebugApp from '@site-docs/components/debug-app';
|
39
40
|
|
40
41
|
<DebugApp />
|
41
42
|
|
@@ -43,7 +44,7 @@ import DebugApp from "@site-docs/components/debug-app"
|
|
43
44
|
|
44
45
|
通过 `@modern-js/create` 创建的 Modern.js 项目中,会默认生成 `modern.config.ts` 文件。
|
45
46
|
|
46
|
-
|
47
|
+
你可以通过该配置文件修改配置,覆盖 Modern.js 的默认行为。例如添加如下配置,开启 SSR:
|
47
48
|
|
48
49
|
```ts title="modern.config.ts"
|
49
50
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
@@ -61,6 +62,26 @@ export default defineConfig({
|
|
61
62
|
|
62
63
|
重新执行 `pnpm run dev`,在浏览器 Network 菜单中,可以发现项目已经在服务端完成了页面渲染。
|
63
64
|
|
65
|
+
## 核心 npm 包
|
66
|
+
|
67
|
+
在新创建的工程中,默认会安装 `@modern-js/app-tools` npm 包,它是 Modern.js 框架的核心包,主要提供以下能力:
|
68
|
+
|
69
|
+
- 提供 `modern dev`, `modern build` 等常用的 CLI 命令。
|
70
|
+
- 集成 Modern.js Core,提供配置解析、插件加载等能力。
|
71
|
+
- 集成 Modern.js Builder,提供构建能力。
|
72
|
+
- 集成 Modern.js Server,提供开发和生产服务器相关能力。
|
73
|
+
- 集成一些最为常用的插件,比如 `plugin-lint`、`plugin-data-loader` 等。
|
74
|
+
|
75
|
+
`@modern-js/app-tools` 是基于 Modern.js 的插件体系实现的,本质上是一个插件,因此你需要在配置文件的 `plugins` 字段中注册 `appTools`:
|
76
|
+
|
77
|
+
```ts title="modern.config.ts"
|
78
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
79
|
+
|
80
|
+
export default defineConfig({
|
81
|
+
plugins: [appTools()],
|
82
|
+
});
|
83
|
+
```
|
84
|
+
|
64
85
|
## 构建项目
|
65
86
|
|
66
87
|
在项目中执行 `pnpm run build` 即可构建项目生产环境产物:
|
@@ -125,6 +146,6 @@ info App running at:
|
|
125
146
|
|
126
147
|
## 部署
|
127
148
|
|
128
|
-
import Deploy from
|
149
|
+
import Deploy from '@site-docs/components/deploy';
|
129
150
|
|
130
151
|
<Deploy />
|
@@ -299,10 +299,21 @@ export const myPlugin = (): CliPlugin => ({
|
|
299
299
|
|
300
300
|
### `beforeCreateCompiler`
|
301
301
|
|
302
|
-
-
|
303
|
-
-
|
304
|
-
-
|
305
|
-
-
|
302
|
+
- 功能:在创建底层 Compiler 实例前触发的回调函数,并且你可以通过 `bundlerConfigs` 参数获取到底层打包工具的最终配置数组:
|
303
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack 配置数组。
|
304
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack 配置数组。
|
305
|
+
- 配置数组中可能包含一份或多份配置,这取决于你是否开启了 SSR 等功能。
|
306
|
+
- 执行阶段:在执行 dev 或 build 命令时,创建 Compiler 实例之前执行
|
307
|
+
- Hook 模型:`AsyncWorkflow`
|
308
|
+
- 类型:
|
309
|
+
|
310
|
+
```ts
|
311
|
+
type BeforeCreateCompiler = AsyncWorkflow<
|
312
|
+
{ bundlerConfigs: Configuration[] },
|
313
|
+
unknown
|
314
|
+
>;
|
315
|
+
```
|
316
|
+
|
306
317
|
- 使用示例:
|
307
318
|
|
308
319
|
```ts
|
@@ -311,8 +322,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
311
322
|
export const myPlugin = (): CliPlugin => ({
|
312
323
|
setup(api) {
|
313
324
|
return {
|
314
|
-
beforeCreateCompiler: ({
|
315
|
-
|
325
|
+
beforeCreateCompiler: ({ bundlerConfigs }) => {
|
326
|
+
console.log('Before create compiler.');
|
327
|
+
console.log(bundlerConfigs);
|
316
328
|
},
|
317
329
|
};
|
318
330
|
},
|
@@ -321,10 +333,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
321
333
|
|
322
334
|
### `afterCreateCompiler`
|
323
335
|
|
324
|
-
-
|
325
|
-
-
|
326
|
-
-
|
327
|
-
-
|
336
|
+
- 功能:在创建 Compiler 实例后、执行构建前触发的回调函数,并且你可以通过 `compiler` 参数获取到 Compiler 实例对象:
|
337
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack Compiler 对象。
|
338
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack Compiler 对象。
|
339
|
+
- 执行阶段:创建 Compiler 对象之后执行
|
340
|
+
- Hook 模型:`AsyncWorkflow`
|
341
|
+
- 类型:
|
342
|
+
|
343
|
+
```ts
|
344
|
+
type AfterCreateCompiler = AsyncWorkflow<
|
345
|
+
{ compiler: Compiler | MultiCompiler | undefined },
|
346
|
+
unknown
|
347
|
+
>;
|
348
|
+
```
|
349
|
+
|
328
350
|
- 使用示例:
|
329
351
|
|
330
352
|
```ts
|
@@ -334,7 +356,8 @@ export const myPlugin = (): CliPlugin => ({
|
|
334
356
|
setup(api) {
|
335
357
|
return {
|
336
358
|
afterCreateCompiler: ({ compiler }) => {
|
337
|
-
|
359
|
+
console.log('After create compiler.');
|
360
|
+
console.log(compiler);
|
338
361
|
},
|
339
362
|
};
|
340
363
|
},
|
@@ -368,10 +391,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
368
391
|
|
369
392
|
### `beforeBuild`
|
370
393
|
|
371
|
-
-
|
372
|
-
-
|
373
|
-
-
|
374
|
-
-
|
394
|
+
- 功能:在执行生产环境构建前触发的回调函数,你可以通过 `bundlerConfigs` 参数获取到底层打包工具的最终配置数组。
|
395
|
+
- 如果当前打包工具为 webpack,则获取到的是 webpack 配置数组。
|
396
|
+
- 如果当前打包工具为 Rspack,则获取到的是 Rspack 配置数组。
|
397
|
+
- 配置数组中可能包含一份或多份配置,这取决于你是否开启了 SSR 等功能。
|
398
|
+
- 执行阶段:运行 `build` 命令后,在开始构建前执行
|
399
|
+
- Hook 模型:`AsyncWorkflow`
|
400
|
+
- 类型:
|
401
|
+
|
402
|
+
```ts
|
403
|
+
type BeforeBuild = AsyncWorkflow<{
|
404
|
+
bundlerConfigs: WebpackConfig[] | RspackConfig[];
|
405
|
+
}>;
|
406
|
+
```
|
407
|
+
|
375
408
|
- 使用示例:
|
376
409
|
|
377
410
|
```ts
|
@@ -380,8 +413,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
380
413
|
export const myPlugin = (): CliPlugin => ({
|
381
414
|
setup(api) {
|
382
415
|
return {
|
383
|
-
beforeBuild: () => {
|
384
|
-
|
416
|
+
beforeBuild: ({ bundlerConfigs }) => {
|
417
|
+
console.log('Before build.');
|
418
|
+
console.log(bundlerConfigs);
|
385
419
|
},
|
386
420
|
};
|
387
421
|
},
|
@@ -390,10 +424,19 @@ export const myPlugin = (): CliPlugin => ({
|
|
390
424
|
|
391
425
|
### `afterBuild`
|
392
426
|
|
393
|
-
-
|
394
|
-
-
|
395
|
-
-
|
396
|
-
-
|
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
|
+
```
|
439
|
+
|
397
440
|
- 使用示例:
|
398
441
|
|
399
442
|
```ts
|
@@ -402,8 +445,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
402
445
|
export const myPlugin = (): CliPlugin => ({
|
403
446
|
setup(api) {
|
404
447
|
return {
|
405
|
-
afterBuild: () => {
|
406
|
-
|
448
|
+
afterBuild: ({ stats }) => {
|
449
|
+
console.log('After build.');
|
450
|
+
console.log(stats);
|
407
451
|
},
|
408
452
|
};
|
409
453
|
},
|
package/package.json
CHANGED
@@ -15,14 +15,14 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.26.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.26.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.26.0",
|
38
|
+
"@modern-js/doc-tools": "2.26.0",
|
39
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.26.0"
|
40
40
|
},
|
41
41
|
"scripts": {
|
42
42
|
"dev": "modern dev",
|