@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.
@@ -1,5 +1,4 @@
1
1
  ---
2
- title: Extending
3
2
  sidebar_position: 5
4
3
  ---
5
4
 
@@ -1,5 +1,4 @@
1
1
  ---
2
- title: Hook List
3
2
  sidebar_position: 8
4
3
  ---
5
4
 
@@ -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,9 +1,8 @@
1
1
  ---
2
- title: Develop Plugins
3
2
  sidebar_position: 3
4
3
  ---
5
4
 
6
- # How to Develop Plugins
5
+ # Develop Plugins
7
6
 
8
7
  The previous section introduced the Hook models used by Modern.js plugins, while this section describes how to develop plugins.
9
8
 
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: Introduction
3
2
  sidebar_position: 1
4
3
  ---
4
+
5
5
  # Introduction
6
6
 
7
7
  ## Modern.js Plugin System
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: Lifecycle
3
2
  sidebar_position: 1
4
3
  ---
4
+
5
5
  # Lifecycle
6
6
 
7
7
  Modern.js application has a complete lifecycle, including CLI, Server Side and Runtime three stages.
@@ -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
- distDirectory: string;
99
+ /** Name of the current project's package.json */
87
100
  packageName: string;
88
- srcDirectory: string;
89
- sharedDirectory: string;
90
- nodeModulesDirectory: string;
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
- htmlTemplates: HtmlTemplates;
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
- # Relationship between Plugins
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: 扩展插件 Hook
3
2
  sidebar_position: 5
4
3
  ---
5
4
 
@@ -1,5 +1,4 @@
1
1
  ---
2
- title: Hook 列表
3
2
  sidebar_position: 8
4
3
  ---
5
4
 
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: Hook 模型
3
2
  sidebar_position: 2
4
3
  ---
4
+
5
5
  # Hook 模型
6
6
 
7
7
  首先介绍一下 Modern.js 的基础的插件系统中的一些内容,包括 Hook 模型的工作方式、各个 Hook 模型的运行模式、Manager 的工作模式。
@@ -1,5 +1,4 @@
1
1
  ---
2
- title: 如何编写插件
3
2
  sidebar_position: 3
4
3
  ---
5
4
 
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 介绍
3
2
  sidebar_position: 1
4
3
  ---
4
+
5
5
  # 介绍
6
6
 
7
7
  ## Modern.js 插件系统
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 生命周期
3
2
  sidebar_position: 1
4
3
  ---
4
+
5
5
  # 生命周期
6
6
 
7
7
  Modern.js 应用具有完整的生命周期,包括 CLI、Server Side 和 Runtime 三个阶段。
@@ -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
- distDirectory: string;
99
+ /** 当前项目 package.json 的 name */
87
100
  packageName: string;
88
- srcDirectory: string;
89
- sharedDirectory: string;
90
- nodeModulesDirectory: string;
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
- htmlTemplates: HtmlTemplates;
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
+ :::
@@ -1,7 +1,7 @@
1
1
  ---
2
- title: 插件之间的关系
3
2
  sidebar_position: 4
4
3
  ---
4
+
5
5
  # 插件之间的关系
6
6
 
7
7
  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-20230925160549",
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-20230925160549"
25
+ "@modern-js/sandpack-react": "0.0.0-nightly-20230926160605"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "0.0.0-nightly-20230925160549"
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-20230925160549",
43
- "@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20230925160549"
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",