Skip to content

Commit 1a9a9b6

Browse files
authored
docs: reference other plugins (#3947)
1 parent 5439dde commit 1a9a9b6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

website/docs/en/plugins/dev/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ export const pluginFoo = (options: PluginFooOptions = {}): RsbuildPlugin => ({
165165
});
166166
```
167167

168+
### Reference Other Plugins
169+
170+
Rsbuild's [plugins](/config/plugins) config supports passing a nested array, which means you can reference and register other Rsbuild plugins within your plugin.
171+
172+
For example, register `pluginBar` within `pluginFoo`:
173+
174+
```ts
175+
import { pluginBar } from 'rsbuild-plugin-bar';
176+
177+
export const pluginFoo = (): RsbuildPlugin => {
178+
const foo = {
179+
name: 'plugin-foo',
180+
setup(api) {
181+
// ...
182+
},
183+
};
184+
return [foo, pluginBar()];
185+
};
186+
```
187+
168188
## Lifetime Hooks
169189

170190
Rsbuild uses lifetime planning work internally, and plugins can also register hooks to take part in any stage of the workflow and implement their own features.

website/docs/zh/plugins/dev/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ export const pluginFoo = (options: PluginFooOptions = {}): RsbuildPlugin => ({
165165
});
166166
```
167167

168+
### 引用其他插件
169+
170+
Rsbuild 的 [plugins](/config/plugins) 配置项支持传入一个嵌套的数组,这意味着你可以通过这种方式在插件内部引用其他 Rsbuild 插件。
171+
172+
例如,在 `pluginFoo` 内部引用并注册 `pluginBar`
173+
174+
```ts
175+
import { pluginBar } from 'rsbuild-plugin-bar';
176+
177+
export const pluginFoo = (): RsbuildPlugin => {
178+
const foo = {
179+
name: 'plugin-foo',
180+
setup(api) {
181+
// ...
182+
},
183+
};
184+
return [foo, pluginBar()];
185+
};
186+
```
187+
168188
## 生命周期钩子
169189

170190
Rsbuild 在内部按照约定的生命周期进行任务调度,插件可以通过注册钩子来介入工作流程的任意阶段,并实现自己的功能。

0 commit comments

Comments
 (0)