Skip to main content
The bundle command builds a JavaScript bundle from your React Native app’s source code, which can be used for production builds or offline distribution.

Usage

Options

Examples

Basic iOS Bundle

Basic Android Bundle

Production Bundle with Source Maps

Bundle for Hermes

Development Bundle

Reset Cache

Platform-Specific Bundling

iOS

Output:
  • ios/main.jsbundle - JavaScript bundle
  • ios/assets/ - Images and other assets

Android

Output:
  • android/app/src/main/assets/index.android.bundle - JavaScript bundle
  • android/app/src/main/res/drawable-* - Images
  • android/app/src/main/res/raw/ - Other assets

Hermes Bytecode

For better performance on Android, compile to Hermes bytecode:

Step 1: Create Bundle

Step 2: Compile to Bytecode

Modern React Native Android builds handle Hermes compilation automatically during the Gradle build process.

Source Maps

Source maps enable debugging of production bundles.

Generate Source Map

Upload to Error Tracking

For services like Sentry:

Debug with Source Map

Asset Handling

Image Assets

Images are automatically resolved and bundled:
After bundling, images are placed in:
  • iOS: assets/ directory
  • Android: res/drawable-* directories (organized by DPI)

iOS Asset Catalog

Generate an Asset Catalog for iOS:

Custom Metro Configuration

Using Custom Config

Metro Config Example

metro.production.config.js

Build Scripts

Add to package.json:
package.json
Run:

Automation

Integrate with Build Process

iOS (Xcode Build Phase)

Add to Xcode Build Phases:
This automatically bundles JavaScript during Xcode builds.

Android (Gradle)

Android builds automatically bundle JavaScript via Gradle tasks. Configure in android/app/build.gradle:
android/app/build.gradle

Optimization

Remove Console Logs

metro.config.js

Inline Requires

metro.config.js

Tree Shaking

Ensure imports are ES6 modules:

Troubleshooting

Bundle Too Large

Solution:
  1. Enable minification:
  1. Use inline requires in Metro config
  2. Remove unused dependencies
  3. Use dynamic imports for large modules

Assets Not Found

Error: Missing images in bundled app Solution: Ensure --assets-dest points to correct directory:
  • iOS: ios/ or ios/YourApp/
  • Android: android/app/src/main/res/

Source Maps Invalid

Solution: Generate source map during same bundle command:

Cache Issues

Solution:

Hermes Compilation Failed

Solution: Ensure you’re using the correct hermesc binary for your platform and that the bundle was created with --unstable-transform-profile hermes.

Bundle Analysis

Check Bundle Size

Analyze Bundle Contents

Use react-native-bundle-visualizer:
Generates an interactive visualization of your bundle.

Environment Variables

Custom Entry File

Custom Node Options

Next Steps

Metro Config

Configure Metro bundler settings

Build Android

Build production Android apps

Build iOS

Build production iOS apps

Performance

Optimize bundle size and performance