@modern-js/main-doc 0.0.0-nightly-20230925160549 → 0.0.0-nightly-20230926160605
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/docs/en/guides/topic-detail/framework-plugin/extend.mdx +0 -1
- package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +0 -1
- package/docs/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/docs/en/guides/topic-detail/framework-plugin/implement.mdx +1 -2
- package/docs/en/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
- package/docs/en/guides/topic-detail/framework-plugin/lifecycle.mdx +1 -1
- package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +31 -11
- package/docs/en/guides/topic-detail/framework-plugin/relationship.mdx +2 -2
- package/docs/zh/guides/topic-detail/framework-plugin/extend.mdx +0 -1
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +0 -1
- package/docs/zh/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/docs/zh/guides/topic-detail/framework-plugin/implement.mdx +0 -1
- package/docs/zh/guides/topic-detail/framework-plugin/introduction.mdx +1 -1
- package/docs/zh/guides/topic-detail/framework-plugin/lifecycle.mdx +1 -1
- package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +31 -11
- package/docs/zh/guides/topic-detail/framework-plugin/relationship.mdx +1 -1
- package/package.json +5 -5
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
title: Hook Model
|
3
2
|
sidebar_position: 2
|
4
3
|
---
|
4
|
+
|
5
5
|
# Hook Model
|
6
6
|
|
7
7
|
First, let's introduce some content about the basic plugin system in Modern.js, including the working mode of the Hook model, the operating mode of each Hook model, and the working mode of the Manager.
|
@@ -1,5 +1,4 @@
|
|
1
1
|
---
|
2
|
-
title: Plugin API
|
3
2
|
sidebar_position: 6
|
4
3
|
---
|
5
4
|
|
@@ -79,26 +78,43 @@ Used to retrieve the runtime context of the application.
|
|
79
78
|
const useAppContext: () => IAppContext;
|
80
79
|
|
81
80
|
interface IAppContext {
|
81
|
+
/** Root directory of the current project */
|
82
82
|
appDirectory: string;
|
83
|
+
/** Source code directory */
|
84
|
+
srcDirectory: string;
|
85
|
+
/** Directory for output files */
|
86
|
+
distDirectory: string;
|
87
|
+
/** Directory for shared modules */
|
88
|
+
sharedDirectory: string;
|
89
|
+
/** Directory for framework temp files */
|
90
|
+
internalDirectory: string;
|
91
|
+
/** node_modules directory */
|
92
|
+
nodeModulesDirectory: string;
|
93
|
+
/** Path to the configuration file */
|
83
94
|
configFile: string | false;
|
95
|
+
/** IPv4 address of the current machine */
|
84
96
|
ip?: string;
|
97
|
+
/** Port number of the development server */
|
85
98
|
port?: number;
|
86
|
-
|
99
|
+
/** Name of the current project's package.json */
|
87
100
|
packageName: string;
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
internalDirectory: string;
|
92
|
-
plugins: {
|
93
|
-
cli?: any;
|
94
|
-
server?: any;
|
95
|
-
}[];
|
101
|
+
/** Currently registered plugins */
|
102
|
+
plugins: any[];
|
103
|
+
/** Information for entry points */
|
96
104
|
entrypoints: Entrypoint[];
|
105
|
+
/** Information for server routes */
|
97
106
|
serverRoutes: ServerRoute[];
|
98
|
-
|
107
|
+
/** Tools type of the current project */
|
108
|
+
toolsType?: 'app-tools' | 'module-tools' | 'monorepo-tools';
|
109
|
+
/** Type of the bundler being used */
|
110
|
+
bundlerType?: 'webpack' | 'rspack' | 'esbuild';
|
99
111
|
}
|
100
112
|
```
|
101
113
|
|
114
|
+
:::tip
|
115
|
+
Some fields in the AppContext are dynamically set and will change as the program runs. Therefore, when plugins read these fields at different times, they may get different values.
|
116
|
+
:::
|
117
|
+
|
102
118
|
### useHookRunners
|
103
119
|
|
104
120
|
Used to retrieve the executor of Hooks and trigger the execution of specific Hooks.
|
@@ -116,3 +132,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
116
132
|
},
|
117
133
|
});
|
118
134
|
```
|
135
|
+
|
136
|
+
:::tip
|
137
|
+
Please avoid executing the built-in hooks, as it may break the internal execution logic of the framework.
|
138
|
+
:::
|
@@ -1,8 +1,8 @@
|
|
1
1
|
---
|
2
|
-
title: Relationship
|
3
2
|
sidebar_position: 4
|
4
3
|
---
|
5
|
-
|
4
|
+
|
5
|
+
# Relationship
|
6
6
|
|
7
7
|
The plugin configuration object in Modern.js provides a series of fields to control plugin order, mutual exclusion, and other capabilities. The available fields are as follows:
|
8
8
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
---
|
2
|
-
title: 插件 API
|
3
2
|
sidebar_position: 6
|
4
3
|
---
|
5
4
|
|
@@ -79,26 +78,43 @@ interface NormalizedConfig {
|
|
79
78
|
const useAppContext: () => IAppContext;
|
80
79
|
|
81
80
|
interface IAppContext {
|
81
|
+
/** 当前项目的根目录 */
|
82
82
|
appDirectory: string;
|
83
|
+
/** 源代码目录 */
|
84
|
+
srcDirectory: string;
|
85
|
+
/** 构建产出输出目录 */
|
86
|
+
distDirectory: string;
|
87
|
+
/** 公共模块目录 */
|
88
|
+
sharedDirectory: string;
|
89
|
+
/** 框架临时文件输出目录 */
|
90
|
+
internalDirectory: string;
|
91
|
+
/** node_modules 目录 */
|
92
|
+
nodeModulesDirectory: string;
|
93
|
+
/** 配置文件路径 */
|
83
94
|
configFile: string | false;
|
95
|
+
/** 当前机器的 IPv4 地址 */
|
84
96
|
ip?: string;
|
97
|
+
/** 开发服务器的端口号 */
|
85
98
|
port?: number;
|
86
|
-
|
99
|
+
/** 当前项目 package.json 的 name */
|
87
100
|
packageName: string;
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
internalDirectory: string;
|
92
|
-
plugins: {
|
93
|
-
cli?: any;
|
94
|
-
server?: any;
|
95
|
-
}[];
|
101
|
+
/** 当前注册的插件 */
|
102
|
+
plugins: any[];
|
103
|
+
/** 页面入口信息 */
|
96
104
|
entrypoints: Entrypoint[];
|
105
|
+
/** 服务端路由信息 */
|
97
106
|
serverRoutes: ServerRoute[];
|
98
|
-
|
107
|
+
/** 当前项目类型 */
|
108
|
+
toolsType?: 'app-tools' | 'module-tools' | 'monorepo-tools';
|
109
|
+
/** 当前使用的打包工具类型 */
|
110
|
+
bundlerType?: 'webpack' | 'rspack' | 'esbuild';
|
99
111
|
}
|
100
112
|
```
|
101
113
|
|
114
|
+
:::tip
|
115
|
+
AppContext 中的部分字段是动态设置的,会随着程序的运行而变化。因此,当插件在不同的时机读取字段时,可能会获取到不同的值。
|
116
|
+
:::
|
117
|
+
|
102
118
|
### useHookRunners
|
103
119
|
|
104
120
|
用于获取 Hooks 的执行器,并触发特定的 Hook 执行。
|
@@ -116,3 +132,7 @@ export const myPlugin = (): CliPlugin => ({
|
|
116
132
|
},
|
117
133
|
});
|
118
134
|
```
|
135
|
+
|
136
|
+
:::tip
|
137
|
+
请尽量避免执行框架内置的 hooks,否则可能会导致框架内部的运行逻辑出错。
|
138
|
+
:::
|
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-20230926160605",
|
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-20230926160605"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
28
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20230926160605"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -39,8 +39,8 @@
|
|
39
39
|
"@rspress/shared": "0.1.1",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "^9",
|
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-20230926160605",
|
43
|
+
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20230926160605"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|