This guide will help you migrate your React Native project from using webpack to Rspack with Re.Pack.
If your project is using version 4 of Re.Pack, you need to migrate it to use Re.Pack 5 first.
See the Migration from Re.Pack 4 guide for more details.
Rspack is a fast Rust-based bundler that's compatible with the webpack ecosystem, offering significantly faster build times for both development and production while maintaining webpack compatibility with minimal migration effort. For more details on why Rspack was created and its advantages, see the official rationale.
package.json
To use Rspack, you'll need to update your dependencies by adding the following:
react-native.config.js
Since Re.Pack now supports multiple bundlers, you need to specify that you want to use Rspack commands explicitly.
Update your react-native.config.js
file to use Rspack commands:
Rename your configuration file to match the Rspack convention:
webpack.config.js
→ rspack.config.js
webpack.config.mjs
→ rspack.config.mjs
webpack.config.cjs
→ rspack.config.cjs
When migrating from webpack to Rspack, you'll need to make several changes to your configuration file.
The modifications outlined below cover the basic changes needed for most React Native projects. However, if you have a more complex webpack setup with custom loaders, plugins, or configurations, these changes might not be sufficient.
For more advanced migration scenarios, refer to the official Rspack migration guide, which provides detailed instructions for migrating various webpack features, plugins, and loaders to their Rspack equivalents.
TerserPlugin
import and configurationRspack uses SwcJsMinimizerRspackPlugin for minification, which is much faster than TerserPlugin
and comes configured by default. You can remove both the TerserPlugin
import and its configuration.
babel-loader
withgetJsTransformRules
Rspack uses SWC for transpilation instead of Babel. The getJsTransformRules()
helper function configures all necessary JavaScript/TypeScript transformation rules.
The getJsTransformRules()
function returns the default rules for transforming JavaScript and TypeScript files using SWC. It handles both your application code and node_modules
, and is functionally equivalent to the official @react-native/babel-preset
. For more details, see the API documentation for getJsTransformRules.
If your project uses Flow for type checking, you'll need to add a dedicated loader since SWC (used by Rspack) doesn't support Flow natively. Re.Pack provides a @callstack/repack/flow-loader
to strip Flow type annotations from your code. Add the following rule to your module configuration:
There is no need to configure Flow support for libraries since getJsTransformRules
handles them out of the box. In rare cases, you may need to configure Flow support for unhandled libraries.
For more details, see our Flow support documentation.
@callstack/repack-plugin-reanimated
If your project uses react-native-reanimated
, we provide an official plugin to ensure optimal performance when bundling with Rspack.
To add the Re.Pack Reanimated plugin to your project:
Then update your Rspack configuration file to include the plugin:
For more details on using Reanimated with Re.Pack & Rspack, see our Reanimated support page.
After migration, you can run the development server using the same command as before:
Same goes for creating a production bundle:
If you are having trouble migrating to Rspack reach out and open an issue on GitHub.
After successfully migrating to Rspack and confirming that your app runs correctly, you can remove webpack-related dependencies that are no longer needed: