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
ios/main.jsbundle- JavaScript bundleios/assets/- Images and other assets
Android
android/app/src/main/assets/index.android.bundle- JavaScript bundleandroid/app/src/main/res/drawable-*- Imagesandroid/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:- 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 topackage.json:
package.json
Automation
Integrate with Build Process
iOS (Xcode Build Phase)
Add to Xcode Build Phases:Android (Gradle)
Android builds automatically bundle JavaScript via Gradle tasks. Configure inandroid/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:- Enable minification:
- Use inline requires in Metro config
- Remove unused dependencies
- 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/orios/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
Usereact-native-bundle-visualizer:
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