Rspack's configuration is designed based on webpack, enabling you to migrate your project from webpack to Rspack with ease.
This document is primarily aimed at projects using webpack 5. Since Rspack's API and configuration align with webpack 5. For projects not using webpack 5, there are other migration guides that can be referenced:
In your project directory, install Rspack as a devDependencies
:
Now you can remove the webpack-related dependencies from your project:
In some cases, you will still need to keep webpack
as a dev dependency, such as when using vue-loader or fork-ts-checker-webpack-plugin.
This is because these plugins directly import
subpaths of webpack and couple with webpack. If you encounter this issue, you can provide feedback to the maintainers of these plugins, asking them if they can make webpack
an optional dependency.
Update your build scripts to use Rspack instead of webpack:
Rename the webpack.config.js
file to rspack.config.js
.
Rspack commands can specify the configuration file with -c
or --config
, similar to webpack commands.
However, unlike webpack, if a configuration file is not explicitly specified, Rspack defaults to using rspack.config.js
.
Rspack does not currently support all webpack configurations, and some configurations might affect the build output.
To ensure the correctness of the build output, Rspack enables strict validation of the configurations by default.
However, Rspack also provides a loose mode for easy progressive migration. You can enable it by setting the RSPACK_CONFIG_VALIDATE
environment variable:
Rspack is actively working on implementing webpack's upcoming features, so some configuration defaults differ from webpack 5, as shown below:
Configuration | webpack Default | Rspack Default |
---|---|---|
node.global | true | 'warn' |
node.__filename | 'mock' | 'warn-mock' |
node.__dirname | 'mock' | 'warn-mock' |
You can refer to Configure Rspack to see the configurations supported by Rspack.
Rspack has implemented most of webpack's built-in plugins, with the same names and configuration parameters, allowing for easy replacement.
For example, replacing the DefinePlugin:
See Webpack-aligned built-in plugins for more information about supported webpack plugins in Rspack.
Rspack supports most of the webpack community plugins and also offers alternative solutions for some currently unsupported plugins.
Check Plugin compat for more information on Rspack's compatibility with popular webpack community plugins.
Rspack's loader runner is fully compatible with webpack's loader functionality, supporting the vast majority of webpack loaders. You can use your existing loaders without any changes. However, to achieve the best performance, consider migrating the following loaders:
Using builtin:swc-loader
offers better performance compared to the babel-loader
and the external swc-loader
, as it avoids frequent communication between JavaScript and Rust.
If you need custom transformation logic using Babel plugins, you can retain babel-loader
, but it is recommended to limit its use to fewer files to prevent significant performance degradation.
Rspack implements Webpack 5's Asset Modules, using asset modules to replace file-loader
, url-loader
, and raw-loader
for better performance.