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 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.The type of the plugin object, which contains the following properties:
You can import this type from @rsbuild/core
:
By default, plugins are executed in the order they are added. You can declare pre-execution plugins using the pre
field.
For example, consider the following two plugins:
The Bar plugin is configured with the Foo plugin in its pre
field, so the Foo plugin will always be executed before the Bar plugin.
Similarly, you can declare post-execution plugins using the post
field.
The Bar plugin is configured with the Foo plugin in its post
field, so the Foo plugin will always be executed after the Bar plugin.
You can remove other plugins within a plugin using the remove
field.
For example, if you register both the Foo and Bar plugins mentioned above, the Foo plugin will not take effect because the Bar plugin declares the removal of the Foo plugin.
api.context
is a read-only object that provides some context information.
The content of api.context
is exactly the same as rsbuild.context
, please refer to rsbuild.context.
Get the Rsbuild config, this method must be called after the modifyRsbuildConfig
hook is executed.
Get the normalized Rsbuild config, this method must be called after the modifyRsbuildConfig
hook is executed.
Compared with the api.getRsbuildConfig
method, the config returned by this method has been normalized, and the type definition of the config will be narrowed. For example, the undefined
type of config.html
will be removed.
It is recommended to use this method to get the Rsbuild config.
Determines whether a plugin has been registered.
Get path information for all HTML assets.
This method will return an object, the key is the entry name and the value is the relative path of the HTML file in the dist directory.