Skip to content

Commit

Permalink
chore: add JS comments for plugin options
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 12, 2024
1 parent b0a48d4 commit 92d4b40
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/compat/plugin-swc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
DEFAULT_BROWSERSLIST,
applyScriptCondition,
type RsbuildPlugin,
type RsbuildPluginAPI,
} from '@rsbuild/shared';
import type { PluginSwcOptions, TransformConfig } from './types';
import {
Expand All @@ -28,7 +27,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({

pre: ['rsbuild:babel', 'uni-builder:babel'],

setup(api: RsbuildPluginAPI) {
setup(api) {
if (api.context.bundlerType === 'rspack') {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/document/docs/en/plugins/dev/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ This section describes the core plugin types and APIs.
The type of the plugin object. The plugin object contains the following properties:

- `name`: The name of the plugin, a unique identifier.
- `setup`: The setup function of the plugin, which can be an asynchronous function. This function will only be executed once when the plugin is initialized. The plugin API provides the context info, utility functions and lifecycle hooks. For a complete introduction to lifecycle hooks, please read the [Plugin Hooks](/plugins/dev/hooks) chapter.
- `pre`: Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
- `post`: Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
- `remove`: Specifies the plugins to be removed. You can pass an array of plugin names to be removed.
- `setup`: The setup function of the plugin, which can be an async function. This function is called once when the plugin is initialized. The plugin API provides the context info, utility functions and lifecycle hooks. For a complete introduction to lifecycle hooks, please read the [Plugin Hooks](/plugins/dev/hooks) chapter.
- `pre`: Declare the names of pre-plugins, which will be executed before the current plugin.
- `post`: Declare the names of post-plugins, which will be executed after the current plugin.
- `remove`: Declare the plugins that need to be removed, you can pass an array of plugin names.

The type of the plugin object, which contains the following properties:

Expand Down
6 changes: 3 additions & 3 deletions packages/document/docs/zh/plugins/dev/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

- `name`:插件的名称,唯一标识符。
- `setup`:插件逻辑的主入口函数,可以是一个异步函数。该函数仅会在初始化插件时执行一次。插件 API 对象上挂载了提供给插件使用的上下文数据、工具函数和注册生命周期钩子的函数,关于生命周期钩子的完整介绍,请阅读 [Plugin Hooks](/plugins/dev/hooks) 章节。
- `pre`指定当前插件的前置插件有哪些,可以传入前置插件 name 的数组,当前插件会被调整到这些插件之后执行
- `post`指定当前插件的后置插件有哪些,可以传入后置插件 name 的数组,当前插件会被调整到这些插件之前执行
- `remove`指定需要移除的插件,可以传入插件 name 的数组。
- `pre`声明前置插件的名称,这些插件会在当前插件之前执行
- `post`声明后置插件的名称,这些插件会在当前插件之后执行
- `remove`声明需要移除的插件,可以传入插件 name 的数组。

```ts
type RsbuildPlugin = {
Expand Down
20 changes: 20 additions & 0 deletions packages/shared/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,31 @@ export type PluginStore = {
pluginAPI?: RsbuildPluginAPI;
};

/**
* The type of the Rsbuild plugin object.
*/
export type RsbuildPlugin = {
/**
* The name of the plugin, a unique identifier.
*/
name: string;
/**
* The setup function of the plugin, which can be an async function.
* This function is called once when the plugin is initialized.
* @param api provides the context info, utility functions and lifecycle hooks.
*/
setup: (api: RsbuildPluginAPI) => PromiseOrNot<void>;
/**
* Declare the names of pre-plugins, which will be executed before the current plugin.
*/
pre?: string[];
/**
* Declare the names of post-plugins, which will be executed after the current plugin.
*/
post?: string[];
/**
* Declare the plugins that need to be removed, you can pass an array of plugin names.
*/
remove?: string[];
};

Expand Down

0 comments on commit 92d4b40

Please sign in to comment.