Vite is an excellent and powerful build tool. In some cases, you might need to migrate a Vite application to Rsbuild. You can refer to this guide to perform the migration.
First, you need to replace the npm dependencies of Vite with Rsbuild's dependencies.
Next, you need to update the npm scripts in your package.json to use Rsbuild's CLI commands.
Create a Rsbuild configuration file rsbuild.config.ts
in the same directory as package.json, and add the following content:
The default build entry points for Rsbuild and Vite are different. Vite uses index.html
as the default entry, while Rsbuild uses src/index.js
.
When migrating from Vite to Rsbuild, you can use Rsbuild's source.entry to set the build entry and html.template to set the template.
Using a newly created Vite project as an example, first delete the <script>
tags from index.html
:
Then add the following config.
Rsbuild will automatically inject the <script>
tags into the generated HTML files during the build process.
Most common Vite plugins can be easily migrated to Rsbuild plugins, such as:
You can refer to Plugin List to learn more about available plugins.
Vite provides import.meta.glob()
for importing multiple modules.
When migrating to Rsbuild, you can use the import.meta.webpackContext() function of Rspack instead:
After completing the above steps, you have completed the basic migration from Vite to Rsbuild. You can now run the npm run serve
command to try starting the dev server.
If you encounter any issues during the build process, please debug according to the error log, or check the Vite configuration to see if there are any necessary configurations that have not been migrated to Rsbuild.
The current document only covers part of the migration process. If you find suitable content to add, feel free to contribute to the documentation via pull request 🤝.
The documentation for rsbuild can be found in the rsbuild/website directory.