This section introduces how to migrate a webpack project to Rsbuild.
First, replace webpack's npm dependencies with Rsbuild's dependencies.
npm remove webpack webpack-cli webpack-dev-servernpm add @rsbuild/core -DNext, update the npm scripts in your package.json to use Rsbuild's CLI commands.
{
"scripts": {
"serve": "webpack serve -c webpack.config.js",
"build": "webpack build -c webpack.config.js",
"dev": "rsbuild dev",
"build": "rsbuild build"
}
}Create an Rsbuild configuration file rsbuild.config.ts in the same directory as package.json, and add the following content:
import { defineConfig } from '@rsbuild/core';
export default defineConfig({
plugins: [],
});See Configure Rsbuild for more.
Webpack projects often include complex webpack.config.js configuration files.
After migrating to Rsbuild, most webpack configurations (such as output, resolve, and module.rules) are built-in and no longer require manual setup.
For the few webpack configurations that need to be migrated, you can choose the following options:
export default {
tools: {
rspack: {
plugins: [new SomeWebpackPlugin()],
},
},
};See Configure Rspack for more.
webpack uses the entry field to set the build entry. In Rsbuild, you can use source.entry to set it.
export default {
source: {
entry: {
foo: './src/pages/foo/index.ts',
bar: './src/pages/bar/index.ts',
},
},
};Because Rsbuild includes common loaders and plugins, you can remove the following dependencies to significantly speed up dependency installation:
The above list covers only some removable dependencies. Real-world webpack projects may include many others, so adjust as needed.
Rsbuild offers a rich set of plugins that provide out-of-the-box support for common scenarios. You can refer to the Plugin List documentation to learn about these plugins.
For example, in a React project, you can integrate Rsbuild plugins as follows. First, remove React-related build dependencies that the Rsbuild React plugin already includes, such as:
react-refresh@babel/preset-react@pmmmwh/react-refresh-webpack-pluginThen follow the React Plugin documentation to register and use it as follows:
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
export default defineConfig({
plugins: [pluginReact()],
});Most common webpack loaders and plugins still work in Rsbuild, but we recommend prioritizing Rsbuild's plugins to simplify your configuration. The following shows how they map:
Rsbuild does not support Rspack's devServer config. See Rspack Dev Server for alternatives.
Rsbuild uses SWC by default, so most commonly used Babel plugins are no longer required. Here are some common Babel plugins migration examples.
@babel/preset-env is no longer required, Rsbuild will automatically downgrade code based on the browserslist configuration.
Note that Rsbuild does not inject polyfill by default. You can refer to Polyfill mode for how to inject.
@babel/preset-typescript is no longer required, as Rsbuild enables SWC's TypeScript transformation by default.
@babel/preset-react is no longer required, replace it with @rsbuild/plugin-react.
@babel/plugin-transform-runtime is no longer required, Rsbuild has built-in equivalent @swc/helpers as runtime helpers.
babel-plugin-import can be replaced with the source.transformImport configuration in Rsbuild.
module.exports = {
plugins: [
[
'import',
{ libraryName: 'some-library', libraryDirectory: 'es', style: true },
],
],
};export default {
source: {
transformImport: [
{ libraryName: 'some-library', libraryDirectory: 'es', style: true },
],
},
};After completing the above steps, you have completed the basic migration from webpack to Rsbuild. You can now run the npm run dev 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 webpack 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.