Version: v5

Migrating to Rspack

This guide will help you migrate your React Native project from using webpack to Rspack with Re.Pack.

⚠️ Migrate to Re.Pack 5 first!

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.

Why migrate to Rspack?

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.

Update dependencies inpackage.json

To use Rspack, you'll need to update your dependencies by adding the following:

npm
yarn
pnpm
bun
npm install -D @rspack/core @swc/helpers

Updatereact-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:

react-native.config.js
module.exports = {
-  commands: require('@callstack/repack/commands/webpack'),
+  commands: require('@callstack/repack/commands/rspack'),
};

Updating configuration

1. Rename your configuration file

Rename your configuration file to match the Rspack convention:

  • 📄 webpack.config.jsrspack.config.js
  • 📄 webpack.config.mjsrspack.config.mjs
  • 📄 webpack.config.cjsrspack.config.cjs

2. Update your configuration

When migrating from webpack to Rspack, you'll need to make several changes to your configuration file.

Additional steps may be required for complex configurations

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.

RemoveTerserPlugin import and configuration

Rspack 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.

- const TerserPlugin = require('terser-webpack-plugin');
  const Repack = require('@callstack/repack');

  module.exports = (env) => {
    return {
-     optimization: {
-       minimizer: [
-         new TerserPlugin({
-           test: /\.(js)?bundle(\?.*)?$/i,
-           extractComments: false,
-           terserOptions: {
-             format: {
-               comments: false,
-             },
-           },
-         }),
-       ],
-     },
    };
  };

Replacebabel-loader withgetJsTransformRules

Rspack uses SWC for transpilation instead of Babel. The getJsTransformRules() helper function configures all necessary JavaScript/TypeScript transformation rules.

module: {
  rules: [
-   {
-     test: /\.[cm]?[jt]sx?$/,
-     use: 'babel-loader',
-     type: 'javascript/auto',
-   },
+   ...Repack.getJsTransformRules(),
    ...Repack.getAssetTransformRules(),
  ],
},
About getJsTransformRules

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.

Configure Flow support (if needed)

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:

rspack.config.cjs
module.exports = {
  module: {
    rules: [
      ...Repack.getJsTransformRules(),
      ...Repack.getAssetTransformRules(),
+     {
+       test: /\.jsx?$/,
+       type: 'javascript/auto',
+       exclude: /node_modules/,
+       use: {
+         loader: '@callstack/repack/flow-loader',
+         options: { all: true },
+       },
+     },
    ],
  },
};
Flow-typed libraries

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.

Use@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:

npm
yarn
pnpm
bun
npm install -D @callstack/repack-plugin-reanimated

Then update your Rspack configuration file to include the plugin:

rspack.config.js
const Repack = require('@callstack/repack');
const { ReanimatedPlugin } = require('@callstack/repack-plugin-reanimated');

module.exports = (env) => {
  return {
    plugins: [
      new Repack.RepackPlugin(),
      new ReanimatedPlugin(),
    ],
  };
};

For more details on using Reanimated with Re.Pack & Rspack, see our Reanimated support page.

Running your app

After migration, you can run the development server using the same command as before:

npm
yarn
pnpm
bun
npx react-native start

Same goes for creating a production bundle:

npm
yarn
pnpm
bun
npx react-native bundle
Having trouble?

If you are having trouble migrating to Rspack reach out and open an issue on GitHub.

Cleanup

After successfully migrating to Rspack and confirming that your app runs correctly, you can remove webpack-related dependencies that are no longer needed:

npm
yarn
pnpm
bun
npm uninstall webpack terser-webpack-plugin