@modern-js/main-doc 0.0.0-nightly-20231213170638 → 0.0.0-nightly-20231214170701
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.
@@ -6,22 +6,69 @@ sidebar_position: 1
|
|
6
6
|
|
7
7
|
## Modern.js Plugin System
|
8
8
|
|
9
|
-
Modern.js
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
9
|
+
Modern.js offers a comprehensive plugin system with a complete lifecycle. Plugins can be used to extend different stages of project operation, request handling, rendering, and more.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Plugins must be explicitly registered in the configuration file to be effective. When you need to add plugins to Modern.js, you can configure them in the `[plugin](/configure/app/plugins.html)` field:
|
14
|
+
|
15
|
+
```ts title="edenx.config.ts"
|
16
|
+
// an example for bff
|
17
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
18
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
19
|
+
|
20
|
+
export default defineConfig({
|
21
|
+
plugins: [appTools(), bffPlugin()],
|
22
|
+
});
|
23
|
+
```
|
24
|
+
|
25
|
+
:::note
|
26
|
+
Note that this configuration only supports adding Modern.js plugins and does not support adding Webpack plugins.
|
27
|
+
:::
|
28
|
+
|
29
|
+
## Official Plugins
|
30
|
+
|
31
|
+
Modern.js offers a range of official plugins, which are integrated with the Modern.js generator. All the functionalities of the official plugins can be enabled by executing the `new` command. For instance, to enable the BFF (Backend For Frontend) feature:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
$ npx modern new
|
35
|
+
? Please select the operation you want: Enable Features
|
36
|
+
? Please select the feature name: (Use arrow keys)
|
37
|
+
Enable Tailwind CSS
|
38
|
+
❯ Enable BFF
|
39
|
+
Enable SSG
|
40
|
+
Enable Micro Frontend
|
41
|
+
Enable Unit Test / Integration Test
|
42
|
+
Enable Visual Testing (Storybook)
|
43
|
+
```
|
44
|
+
|
45
|
+
After the selection is completed, the Modern.js generator will automatically install the corresponding plugins and third-party dependencies. Upon completion of the installation, you will see:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
[INFO] Dependency automatic installation succeeded
|
49
|
+
|
50
|
+
[INFO] install plugin dependencies success!add follow code to modern.config.ts :
|
51
|
+
|
52
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
53
|
+
import { expressPlugin } from '@modern-js/plugin-express';
|
54
|
+
|
55
|
+
export default defineConfig({
|
56
|
+
...,
|
57
|
+
plugins: [..., bffPlugin(), expressPlugin()],
|
58
|
+
});
|
59
|
+
```
|
60
|
+
|
61
|
+
At this point, you can add the plugin to the configuration file according to the output in the console.
|
62
|
+
|
63
|
+
## Composition
|
64
|
+
|
65
|
+
The Modern.js plugin system is mainly divided into three parts: Hook model, Manager, and Context Sharing Mechanism.
|
66
|
+
|
67
|
+
- The Hook model is used to determine the execution logic of the current Hook.
|
68
|
+
- The Manager controls the execution and scheduling of Hooks.
|
69
|
+
- The Context Sharing Mechanism is used to pass information between different Hooks.
|
70
|
+
|
71
|
+
Currently, Modern.js offers several different Hook models: **Pipeline, Waterfall, Workflow**.
|
25
72
|
|
26
73
|
:::note
|
27
74
|
Subsequent chapters will introduce the execution methods of each model in detail.
|
@@ -6,29 +6,74 @@ sidebar_position: 1
|
|
6
6
|
|
7
7
|
## Modern.js 插件系统
|
8
8
|
|
9
|
-
Modern.js
|
9
|
+
Modern.js 提供了一套拥有完整生命周期的插件系统。插件可用于扩展项目运行、请求、渲染等不同阶段功能,
|
10
10
|
|
11
|
-
|
11
|
+
## 使用方式
|
12
12
|
|
13
|
-
|
13
|
+
插件需要在配置文件中显示注册才能够生效,当需要为 Modern.js 添加插件时,可以将它配置到 [plugin](/configure/app/plugins.html) 字段中:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- Parallel(Async)
|
15
|
+
```ts title="edenx.config.ts"
|
16
|
+
// an example for bff
|
17
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
18
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
19
|
+
|
20
|
+
export default defineConfig({
|
21
|
+
plugins: [appTools(), bffPlugin()],
|
22
|
+
});
|
23
|
+
```
|
25
24
|
|
26
25
|
:::note
|
27
|
-
|
26
|
+
注意,该配置仅支持添加 Modern.js 插件,无法添加 Webpack 插件。
|
27
|
+
:::
|
28
|
+
|
29
|
+
## 官方插件
|
30
|
+
|
31
|
+
Modern.js 提供了一系列官方插件,并与 Modern.js 生成器结合。所有的官方插件功能,都可以通过执行 `new` 命令开启。例如当需要开启 BFF 功能时:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
$ npx modern new
|
35
|
+
? 请选择你想要的操作 启用可选功能
|
36
|
+
? 请选择功能名称 (Use arrow keys)
|
37
|
+
启用 「Tailwind CSS」 支持
|
38
|
+
❯ 启用「BFF」功能
|
39
|
+
启用「微前端」模式
|
40
|
+
启用「单元测试 / 集成测试」功能
|
41
|
+
启用「Visual Testing (Storybook)」模式
|
42
|
+
```
|
43
|
+
|
44
|
+
完成选择后,Modern.js 生成器会自动安装对应的插件和三方依赖,安装完成后可以看到:
|
45
|
+
|
46
|
+
```bash
|
47
|
+
[INFO] 依赖自动安装成功
|
48
|
+
|
49
|
+
[INFO] 安装插件依赖成功!请添加如下代码至 modern.config.ts :
|
28
50
|
|
51
|
+
import { bffPlugin } from '@modern-js/plugin-bff';
|
52
|
+
import { expressPlugin } from '@modern-js/plugin-express';
|
53
|
+
|
54
|
+
export default defineConfig({
|
55
|
+
...,
|
56
|
+
plugins: [..., bffPlugin(), expressPlugin()],
|
57
|
+
});
|
58
|
+
```
|
59
|
+
|
60
|
+
此时,可以按照控制台的输出,将插件添加到配置文件中。
|
61
|
+
|
62
|
+
## 插件系统组成
|
63
|
+
|
64
|
+
Modern.js 插件系统主要分为三个部分:Hook 模型、管理器,上下文共享机制。
|
65
|
+
|
66
|
+
- Hook 模型用于确定当前 Hook 的执行逻辑。
|
67
|
+
- 管理器用于控制 Hook 的执行与调度。
|
68
|
+
- 上下文共享机制用于在不同 Hook 间传递信息。
|
69
|
+
|
70
|
+
目前 Modern.js 提供几种不同的 Hook 模型:**Pipeline、Waterfall、Workflow**。
|
71
|
+
|
72
|
+
:::note
|
73
|
+
后续章节详细介绍各个模型的执行方式。
|
29
74
|
:::
|
30
75
|
|
31
|
-
基于 Hook
|
76
|
+
Modern.js 基于 Hook 模型暴露了三套插件:CLI、Runtime、Server。
|
32
77
|
|
33
78
|
其中 CLI 插件是 Modern.js 中主要的运行流程控制模型,Modern.js 中绝大部分功能都是主要通过这一套模型运行的。Runtime 插件主要负责处理 React 组件渲染逻辑。Server 插件主要用于对服务端的生命周期以及用户请求的控制。
|
34
79
|
|
@@ -48,4 +93,4 @@ Modern.js 的所有功能都是通过这套插件实现的,这意味着 Modern
|
|
48
93
|
- 自定义 React 组件客户端/服务器端渲染
|
49
94
|
- ...
|
50
95
|
|
51
|
-
当 Modern.js
|
96
|
+
当 Modern.js 暂时没有覆盖到所需要的功能或场景时,可以开发一个自定义插件,来实现适配特殊场景的相关功能。
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20231214170701",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "0.0.0-nightly-
|
25
|
+
"@modern-js/sandpack-react": "0.0.0-nightly-20231214170701"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
28
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20231214170701"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -39,8 +39,8 @@
|
|
39
39
|
"@rspress/shared": "1.8.2",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "9.0.13",
|
42
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
43
|
-
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-
|
42
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20231214170701",
|
43
|
+
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20231214170701"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|