Skip to content

Commit 04e5950

Browse files
authored
Merge branch 'main' into release-v2.67.5
2 parents b0138d1 + 11de425 commit 04e5950

File tree

10 files changed

+158
-67
lines changed

10 files changed

+158
-67
lines changed

packages/document/main-doc/docs/en/configure/app/plugins.mdx

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
1-
---
2-
sidebar_position: 9
3-
---
4-
51
# plugins
62

73
- **Type:** `CliPlugin[]`
84
- **Default:** `[]`
95

10-
Used to configure custom Modern.js framework plugins.
11-
12-
Refer to [How to Develop Plugins](/plugin/plugin-system) for how to write custom plugins.
6+
Used to configure custom Modern.js framework CLI plugins. For information on how to create custom CLI plugins, please refer to [How to Write CLI Plugins](/plugin/introduction.html#cli-plugins).
137

148
## Note
159

16-
This option is used to configure framework plugins. If you need to configure other types of plugins, please choose the corresponding configuration method:
17-
18-
- Use [builderPlugins](/configure/app/builder-plugins) to configure Rsbuild plugins.
19-
- Use [tools.bundlerChain](/configure/app/tools/bundler-chain) to configure Rspack or webpack plugins.
20-
- Use [tools.babel](/configure/app/tools/babel) to configure Babel plugins.
21-
22-
## Plugin types
23-
24-
Modern.js has three types of plugins:
25-
26-
- `CLI plugins`, applicable to local development, compilation and construction stages, can extend various capabilities in the command line and compilation stages.
27-
- `Server plugins`, applicable to the server.
28-
- `Runtime plugins`, applicable to the front-end runtime.
29-
30-
Currently, Modern.js has opened up the ability to customize CLI plugins, and Server plugins and Runtime plugins will be opened up later.
31-
32-
## Plugin execution order
10+
This option is **specifically for configuring framework CLI plugins**. If you need to configure other types of plugins, use the appropriate configuration method:
3311

34-
By default, custom plugins are executed in the order of the `plugins` array, and the execution time of built-in Modern.js plugins is earlier than that of custom plugins.
12+
- Use [builderPlugins](/configure/app/builder-plugins) for Rsbuild plugins.
13+
- Use [tools.bundlerChain](/configure/app/tools/bundler-chain) for Rspack or webpack plugins.
14+
- Use [tools.babel](/configure/app/tools/babel) for Babel plugins.
15+
- Use the [plugins field in runtime config](/configure/app/runtime/plugins) for framework Runtime plugins.
3516

36-
When the plugin sets options that control the order, such as `pre` and `post`, the execution order will be adjusted based on the declared fields. Refer to [Plugins Structure](/plugin/plugin-system) for more information.
3717

38-
## Example
18+
## Examples
3919

40-
The following is an example of using CLI plugins.
20+
Below are examples of using CLI plugins:
4121

42-
### Use plugins on npm
22+
### Using plugins from npm
4323

44-
To use plugins from npm registry, you need to first install the plugins , and import them in `modern.config.ts`.
24+
To use plugins from the npm registry, first install the plugins and then import them in your configuration:
4525

4626
```ts title="modern.config.ts"
4727
import { myPlugin } from 'my-plugin';
@@ -51,9 +31,9 @@ export default defineConfig({
5131
});
5232
```
5333

54-
### Use local plugins
34+
### Using local plugins
5535

56-
To use local plugins, import them directly using a relative path.
36+
To use plugins from your local repository, import them directly using a relative path:
5737

5838
```ts title="modern.config.ts"
5939
import { myPlugin } from './config/plugin/myPlugin';
@@ -65,7 +45,7 @@ export default defineConfig({
6545

6646
### Plugin configuration
6747

68-
If the plugin provides some custom configuration options, they can be passed in as parameters to the plugin function.
48+
If a plugin provides custom configuration options, pass them as parameters to the plugin function:
6949

7050
```ts title="modern.config.ts"
7151
import { myPlugin } from 'my-plugin';

packages/document/main-doc/docs/en/configure/app/runtime/master-app.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
---
2-
title: masterApp
3-
---
4-
5-
# runtime.masterApp
1+
# masterApp
62

73
- **Type:** `Object`
84

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# plugins
2+
3+
- **Type:** `RuntimePlugin[]`
4+
- **Default:** `[]`
5+
6+
Used to configure custom Modern.js Runtime plugins. For details on how to create custom Runtime plugins, please refer to [How to Write Runtime Plugins](/plugin/introduction#runtime-plugins).
7+
8+
:::info
9+
10+
Runtime plugins must be configured in the `plugins` array within the `src/modern.runtime.ts` file.
11+
12+
:::
13+
14+
## Examples
15+
16+
Here are examples demonstrating how to use Runtime plugins:
17+
18+
### Using plugins from npm packages
19+
20+
To use plugins published on npm, first install them via your package manager, then import them into your configuration.
21+
22+
```ts title="src/modern.runtime.ts"
23+
import { defineRuntimeConfig } from '@modern-js/runtime';
24+
import { myPlugin } from 'my-plugin';
25+
26+
export default defineRuntimeConfig({
27+
plugins: [myPlugin()],
28+
});
29+
```
30+
31+
### Using local plugins
32+
33+
To use plugins from your local codebase, import them directly using relative paths.
34+
35+
```ts title="src/modern.runtime.ts"
36+
import { defineRuntimeConfig } from '@modern-js/runtime';
37+
import { myPlugin } from './config/plugin/myPlugin';
38+
39+
export default defineRuntimeConfig({
40+
plugins: [myPlugin()],
41+
});
42+
```
43+
44+
### Plugin configuration
45+
46+
If a plugin supports custom configuration options, you can provide them as arguments to the plugin function.
47+
48+
```ts title="src/modern.runtime.ts"
49+
import { defineRuntimeConfig } from '@modern-js/runtime';
50+
import { myPlugin } from './config/plugin/myPlugin';
51+
52+
export default defineRuntimeConfig({
53+
plugins: [myPlugin({
54+
foo: 1,
55+
bar: 2,
56+
})],
57+
});
58+
```

packages/document/main-doc/docs/en/plugin/cli-plugins/api.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This document details the API for Modern.js CLI plugins. CLI plugins allow you to extend and customize the functionality of Modern.js projects during the build and development process.
44

5+
:::info
6+
7+
CLI plugins need to be configured via the [`plugins`](/configure/app/plugins) field in `modern.config.ts`.
8+
9+
:::
10+
511
## Plugin Basic Structure
612

713
A typical CLI plugin structure is as follows:

packages/document/main-doc/docs/en/plugin/runtime-plugins/api.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Modern.js's Runtime Plugins allow you to extend and modify the behavior of your application during its React code execution. With Runtime Plugins, you can easily perform initialization tasks, implement React Higher-Order Component (HOC) wrapping, and more.
44

5+
:::info
6+
7+
Runtime plugins need to be configured via the [`plugins`](/configure/app/runtime/plugins) field in `src/modern.runtime.ts`.
8+
9+
:::
10+
511
## Plugin Structure
612

713
A typical Runtime Plugin looks like this:

packages/document/main-doc/docs/zh/configure/app/plugins.mdx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
1-
---
2-
sidebar_position: 9
3-
---
4-
51
# plugins
62

73
- **类型:** `CliPlugin[]`
84
- **默认值:** `[]`
95

10-
用于配置自定义的 Modern.js 框架插件。
11-
12-
自定义插件的编写方式请参考 [如何编写插件](/plugin/plugin-system)
6+
用于配置自定义的 Modern.js 框架 CLI 插件。自定义 CLI 插件的编写方式请参考 [如何编写 CLI 插件](/plugin/introduction.html#cli-插件)
137

148
## 注意事项
159

16-
该选项**用于配置框架插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
10+
该选项**用于配置框架 CLI 插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
1711

1812
- 配置 Rsbuild 插件,请使用 [builderPlugins](/configure/app/builder-plugins) 配置项。
1913
- 配置 Rspack 或 webpack 插件,请使用 [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
2014
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
21-
22-
## 插件类型
23-
24-
Modern.js 中内置了三种不同的框架插件:
25-
26-
- `CLI 插件`,适用于本地开发、编译构建阶段,可以在命令行和编译阶段扩展各种能力。
27-
- `Server 插件`,适用于服务端。
28-
- `Runtime 插件`,适用于前端运行时。
29-
30-
目前 Modern.js 开放了自定义 CLI 插件的能力,Server 插件和 Runtime 插件会在后续开放。
31-
32-
## 插件执行顺序
33-
34-
默认情况下,自定义插件会按照 `plugins` 数组的顺序依次执行,Modern.js 内置插件的执行时机早于自定义插件。
35-
36-
当插件内部使用了控制顺序的相关字段,比如 `pre``post` 时,会基于声明的字段对执行顺序进行调整,详见 [插件结构](/plugin/plugin-system)
15+
- 配置框架 Runtime 插件,请使用 [runtime 配置文件 plugins](/configure/app/runtime/plugins) 配置项。
3716

3817
## 示例
3918

packages/document/main-doc/docs/zh/configure/app/runtime/master-app.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
---
2-
title: masterApp
3-
---
4-
5-
# runtime.masterApp
1+
# masterApp
62

73
- **类型:** `Object`
84

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# plugins
2+
3+
- **类型:** `RuntimePlugin[]`
4+
- **默认值:** `[]`
5+
6+
用于配置自定义的 Modern.js Runtime 插件。自定义 Runtime 插件的编写方式请参考 [如何编写 Runtime 插件](/plugin/introduction.html#runtime-插件)
7+
8+
:::info
9+
10+
Runtime 插件需要在 `src/modern.runtime.ts` 文件中的 plugins 中进行配置。
11+
12+
:::
13+
14+
## 示例
15+
16+
下面是 Runtime 插件的使用示例。
17+
18+
### 使用 npm 上的插件
19+
20+
使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。
21+
22+
```ts title="src/modern.runtime.ts"
23+
import { defineRuntimeConfig } from '@modern-js/runtime';
24+
import { myPlugin } from 'my-plugin';
25+
26+
export default defineRuntimeConfig({
27+
plugins: [myPlugin()],
28+
});
29+
```
30+
31+
### 使用本地插件
32+
33+
使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。
34+
35+
```ts title="src/modern.runtime.ts"
36+
import { defineRuntimeConfig } from '@modern-js/runtime';
37+
import { myPlugin } from './config/plugin/myPlugin';
38+
39+
export default defineRuntimeConfig({
40+
plugins: [myPlugin()],
41+
});
42+
```
43+
44+
### 插件配置项
45+
46+
如果插件提供了一些自定义的配置项,可以通过插件函数的参数传入配置。
47+
48+
```ts title="src/modern.runtime.ts"
49+
import { defineRuntimeConfig } from '@modern-js/runtime';
50+
import { myPlugin } from './config/plugin/myPlugin';
51+
52+
export default defineRuntimeConfig({
53+
plugins: [myPlugin({
54+
foo: 1,
55+
bar: 2,
56+
})],
57+
});
58+
```

packages/document/main-doc/docs/zh/plugin/cli-plugins/api.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
本文档详细介绍了 Modern.js CLI 插件的 API。CLI 插件允许您在 Modern.js 项目的构建和开发过程中扩展和定制功能。
44

5+
:::info
6+
7+
CLI 插件需要通过 `modern.config.ts` 中的 [`plugins`](/configure/app/plugins) 字段配置。
8+
9+
:::
10+
511
## 插件基础结构
612

713
一个典型的 CLI 插件结构如下:

packages/document/main-doc/docs/zh/plugin/runtime-plugins/api.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Modern.js 的 Runtime 插件允许您在应用程序的 React 代码运行时扩展和修改其行为。通过 Runtime 插件,您可以轻松地执行初始化任务、实现 React 高阶组件(HOC)封装等功能。
44

5+
:::info
6+
7+
Runtime 插件需要通过 `src/modern.runtime.ts` 中的 [`plugins`](/configure/app/runtime/plugins) 字段配置。
8+
9+
:::
10+
511
## 插件结构
612

713
一个典型的 Runtime 插件如下所示:

0 commit comments

Comments
 (0)