Vite plugin
This chapter introduces how to migrate a Vite plugin to Rsbuild plugin.
Existing plugins
Before migrating a Vite plugin, it is recommended to check if there is a corresponding plugin in the Rsbuild ecosystem. You can find the plugins through the following pages:
Define a plugin
Rsbuild plugin is defined in a way similar to Vite, usually a function that accepts plugin options as a parameter and returns a plugin description object.
The main difference is that Vite's hooks are defined directly on the plugin description object, while Rsbuild's hooks are accessed and called through the api object. This allows you to control the timing of plugin API calls more flexibly.
- Vite plugin:
- Rsbuild plugin:
Plugin hooks
Rsbuild's plugin API covers most of the Vite and Rollup plugin hooks, for example:
See Plugin system for more details.
config hook
Rsbuild provides the modifyRsbuildConfig hook to modify Rsbuild configuration. Since Rsbuild and Vite have different configuration structures, you'll need to adjust your configuration when migrating Vite plugins.
For example, you should replace Vite's define option with Rsbuild's source.define option.
- Vite plugin:
- Rsbuild plugin:
See Config migration to learn how to migrate Vite configurations to Rsbuild.
configEnvironment hook
Rsbuild provides the modifyEnvironmentConfig hook to modify the configuration of a specific environment.
- Vite plugin:
- Rsbuild plugin:
configResolved hook
Rsbuild provides the api.getNormalizedConfig method to get the resolved configuration. This method serves a similar purpose to Vite's configResolved hook.
- Vite plugin:
- Rsbuild plugin:
transformIndexHtml hook
Vite's transformIndexHtml hook corresponds to two hooks in Rsbuild:
- modifyHTML: for modifying HTML content
- modifyHTMLTags: for modifying HTML tags
Here is an example of replacing the HTML title.
- Vite Plugin:
- Rsbuild Plugin:
configureServer hook
Rsbuild provides the onBeforeStartDevServer hook to replace Vite's configureServer hook, which allows you to get the dev server instance and add custom middleware.
- Vite plugin:
- Rsbuild plugin:
apply property
Rsbuild plugin provides the same apply property as Vite plugins.
- Vite plugin:
- Rsbuild plugin:

