Version: v5

Migrating from Metro

If the automatic migration using @callstack/repack-init didn't work for any reason, or if you have custom project structure, you can follow these manual migration steps:

1. Dependencies

Install required dependencies in your project:

Rspack
webpack
npm
yarn
pnpm
bun
npm install -D @rspack/core @swc/helpers @callstack/repack

This will install the latest versions of your chosen bundler and necessary dependencies for code optimization and minification.

Once the dependencies are installed, you need to tell React Native Community CLI to add Re.Pack's commands.

2. Commands

Add the following content to react-native.config.js (or create it if it doesn't exist):

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

This will allow you to use Re.Pack when running react-native start and react-native bundle commands.

3. Configuration

Pick one of the templates below and create configuration file in the root directory of your project. The name of the file should be identical to the one on top of the template e.g. rspack.config.mjs.

Rspack ESM
Rspack CJS
webpack ESM
webpack CJS
Go with ESM config by default

We recommend to use ESM version of Rspack/webpack config with the .mjs extension. However, Re.Pack also supports ESM under .js and CJS variant under .js and .cjs extensions. Check our templates for CJS and ESM variants as well as the documentation on Configuration to see the list of all available Rspack/webpack config location and extensions.

4. Configure XCode

When building release version of your application XCode project will still use Metro to bundle the application, so you need to adjust build settings to make XCode use Re.Pack instead.

Open your application's Xcode project/workspace and:

  1. Click on the project in Project navigator panel on the left
  2. Go to Build Phases tab
  3. Expand Bundle React Native code and images phase
  4. Add following content to the phase:
if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi

export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native-community/cli/package.json')) + '/build/bin.js'")"

After the change, the content of this phase should look similar to:

Bundle
set -e

WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"

if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then
source "$PODS_ROOT/../.xcode.env"
fi
if [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then
source "$PODS_ROOT/../.xcode.env.local"
fi

export CLI_PATH="$("$NODE_BINARY" --print "require('path').dirname(require.resolve('@react-native-community/cli/package.json')) + '/build/bin.js'")"

/bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"

5. Install CocoaPods dependencies

For iOS development, you need to install CocoaPods dependencies. From the project root directory run:

npx pod-install

This will install all the necessary iOS dependencies for your project, including the Re.Pack native module.

🎉 Congratulations!

You've successfully set up Re.Pack in your project. We highly recommend to check out the following:

Need to boost your app's performance?
We help React Native teams enhance speed, responsiveness, and efficiency.