A comprehensive React Native super app demonstrating Module Federation V2 with Re.Pack 5.x, showcasing micro-frontend architecture patterns and advanced bundle management.
- Architecture Overview
- Key Learnings
- Dependencies & Tooling
- Project Structure
- Setup & Installation
- Development Workflow
- Configuration Deep Dive
- Troubleshooting
- Performance Optimization
This project demonstrates a Module Federation V2 super app architecture with the following micro-frontends:
graph TB
Host[Travel Host App<br/>Port: 8081] --> Weather[Weather MF<br/>Port: 9000]
Host --> Destinations[Destinations MF<br/>Port: 9001]
Host --> Search[Search MF<br/>Port: 9002]
Host --> Photos[Photos MF<br/>Port: 9003]
Host --> Core[travel-core<br/>Shared Package]
Weather --> Core
Destinations --> Core
Search --> Core
Photos --> Core
Host --> SDK[travel-sdk<br/>Dependency Manager]
- โ Manifest-Based Resolution: Automatic remote discovery via JSON manifests
- โ
Platform Agnostic: Dynamic
${platform}interpolation for iOS/Android - โ Zero Configuration: No custom resolvers or URL management needed
- โ Version Management: Built-in caching and dependency sharing
- โ Developer Experience: Hot reloading across micro-frontends
- โ Type Safety: Enhanced TypeScript integration
MF V2's manifest system (mf-manifest.json) provides:
- Automatic remote discovery
- Platform-specific resolution (
${platform}interpolation) - Built-in version management
- Zero configuration complexity
// Simple, declarative configuration
remotes: {
TravelWeather: `TravelWeather@http://localhost:9000/${platform}/mf-manifest.json`,
TravelDestinations: `TravelDestinations@http://localhost:9001/${platform}/mf-manifest.json`
}The combination delivers:
- Fast builds with Rspack's Rust-based bundling
- Hot reloading across micro-frontends
- Tree shaking for optimal bundle sizes
- Hermes bytecode support for production
The enhanced plugin provides:
- Manifest-based resolution: No manual URL management
- Dynamic type hinting: Better TypeScript integration
- Runtime plugin system: Extensible architecture
- Built-in optimization: Automatic dependency sharing
| Package | Version | Purpose |
|---|---|---|
@callstack/repack |
^5.1.1 |
React Native bundling with Module Federation |
@module-federation/enhanced |
^0.13.1 |
Enhanced MF features |
@rspack/core |
^1.2.2 |
Fast Rust-based bundler |
@rnef/cli |
^0.7.5 |
React Native Enhanced Framework |
@swc/helpers |
0.5.15 |
SWC transformation helpers |
zephyr-repack-plugin |
0.0.54 |
Advanced Re.Pack optimizations |
| Tool | Purpose | Configuration |
|---|---|---|
| pnpm | Package manager with workspace support | pnpm-workspace.yaml |
| nx | Monorepo tooling and task orchestration | nx.json |
| mprocs | Multi-process development server | mprocs.yaml |
- React Native:
0.79.5(New Architecture/Fabric) - React:
19.0.0 - Expo:
~53.0.20 - Node.js:
>=22(engineStrict)
travel-app-repack-example/
โโโ ๐ฑ apps/ # Micro-frontend applications
โ โโโ travel-host/ # Main host app (Port: 8081)
โ โ โโโ rspack.config.mjs # MF V2 host configuration
โ โ โโโ rnef.config.mjs # RNEF platform setup
โ โ โโโ src/navigation/ # App navigation
โ โโโ travel-weather/ # Weather MF (Port: 9000)
โ โโโ travel-destinations/ # Destinations MF (Port: 9001)
โ โโโ travel-search/ # Search MF (Port: 9002)
โ โโโ travel-photos/ # Photos MF (Port: 9003)
โโโ ๐ฆ packages/ # Shared packages
โ โโโ travel-core/ # Core utilities & components
โ โ โโโ src/components/ # Shared UI components
โ โ โโโ src/context/ # Global state management
โ โ โโโ src/utils/ # Utility functions
โ โโโ travel-sdk/ # Dependency management SDK
โ โโโ lib/dependencies.json # Centralized dependency versions
โ โโโ lib/sharedDeps.js # MF shared dependencies factory
โโโ โ๏ธ Configuration Files
โ โโโ nx.json # Nx workspace configuration
โ โโโ mprocs.yaml # Multi-process dev setup
โ โโโ pnpm-workspace.yaml # PNPM workspace definition
โ โโโ tsconfig.json # Root TypeScript config
โโโ ๐ docs/ # Documentation
# Required versions
node --version # >= 22.0.0
pnpm --version # >= 10.10.0# 1. Clone and install dependencies
git clone <repository-url>
cd travel-app-repack-example
pnpm install
# 2. iOS setup (if developing for iOS)
cd apps/travel-host/ios
pod install
cd ../../..
# 3. Start all micro-frontends
pnpm start # Uses mprocs for orchestration
# Alternative: Start individually
pnpm start:travel-host # Host app
pnpm start:travel-weather # Weather MF
pnpm start:travel-destinations # Destinations MF
pnpm start:travel-search # Search MF
pnpm start:travel-photos # Photos MF# iOS
pnpm run:travel-host:ios
# Android
pnpm run:travel-host:android# Start all services with mprocs
pnpm startThis launches:
- Host app on port 8081
- Weather MF on port 9000
- Destinations MF on port 9001
- Search MF on port 9002
- Photos MF on port 9003
# Terminal 1: Host
pnpm start:travel-host
# Terminal 2: Specific micro-frontend
pnpm start:travel-weatherEach micro-frontend can run independently:
pnpm start:standalone:travel-weather// apps/travel-host/rspack.config.mjs
new Repack.plugins.ModuleFederationPluginV2({
name: 'TravelHost',
dts: false,
remotes: {
// Platform-specific manifest URLs
TravelWeather: `TravelWeather@http://localhost:9000/${platform}/mf-manifest.json`,
TravelDestinations: `TravelDestinations@http://localhost:9001/${platform}/mf-manifest.json`,
TravelSearch: `TravelSearch@http://localhost:9002/${platform}/mf-manifest.json`,
TravelPhotos: `TravelPhotos@http://localhost:9003/${platform}/mf-manifest.json`,
},
shared: getSharedDependencies({ eager: true }),
});// apps/travel-weather/rspack.config.mjs
new Repack.plugins.ModuleFederationPluginV2({
name: 'TravelWeather',
filename: 'TravelWeather.container.js.bundle',
dts: false,
exposes: {
'./WeatherScreen': './src/WeatherScreen',
},
shared: getSharedDependencies({ eager: false }),
});// rnef.config.mjs
export default {
bundler: pluginRepack(),
platforms: {
ios: platformIOS(),
android: platformAndroid(),
},
remoteCacheProvider: null,
};// packages/travel-sdk/lib/sharedDeps.js
const getSharedDependencies = ({ eager = true }) => {
const dependencies = require('./dependencies.json');
const shared = Object.entries(dependencies).map(([dep, { version }]) => {
return [dep, { singleton: true, eager, requiredVersion: version, version }];
});
return Object.fromEntries(shared);
};// nx.json
{
"workspaceLayout": {
"appsDir": "apps",
"libsDir": "packages"
},
"targetDefaults": {
"bundle:ios": { "outputs": ["{projectRoot}/build"], "cache": true },
"bundle:android": { "outputs": ["{projectRoot}/build"], "cache": true }
}
}# mprocs.yaml
procs:
Host:
shell: pnpm start:travel-host
stop: SIGKILL
Weather:
shell: pnpm start:travel-weather
stop: SIGKILL
# ... other micro-frontendsIssue: Remote manifests fail to load
Debug Steps:
# Check if manifest is accessible
curl http://localhost:9000/android/mf-manifest.json
# Verify manifest structure
cat apps/travel-weather/dist/android/mf-manifest.jsonSolution: Ensure remote is running and ports are correct
Issue: Multiple services trying to use the same port
Solution: Check port allocation in package.json scripts:
- Host: 8081
- Weather: 9000
- Destinations: 9001
- Search: 9002
- Photos: 9003
Issue: Incorrect platform detection in manifest URLs
Solution: Verify platform interpolation:
// Ensure ${platform} resolves correctly
remotes: {
TravelWeather: `TravelWeather@http://localhost:9000/${platform}/mf-manifest.json`;
}Issue: Version conflicts between host and remotes
Solution: Use centralized dependency management:
// packages/travel-sdk/lib/dependencies.json
{
"react": { "version": "19.0.0" },
"react-native": { "version": "0.79.5" }
}Issue: Remote bundles fail to load
Debug Steps:
# Check manifest accessibility
curl http://localhost:9000/android/mf-manifest.json
# Monitor network requests
adb logcat | grep -i "module federation"
# Enable MF debugging
console.log('MF V2 Debug:', window.__FEDERATION__);// Enable Hermes bytecode for production
new Repack.plugins.HermesBytecodePlugin({
enabled: mode === 'production',
test: /\.(js)?bundle$/,
exclude: /index.bundle$/,
});// Host: Eager loading for core dependencies
shared: getSharedDependencies({ eager: true });
// Remotes: Lazy loading for optimal startup
shared: getSharedDependencies({ eager: false });// Optional: Advanced optimizations
const USE_ZEPHYR = Boolean(process.env.ZC);
export default USE_ZEPHYR ? withZephyr()(config) : config;// nx.json - Enable build caching
"targetDefaults": {
"bundle:ios": { "cache": true },
"bundle:android": { "cache": true }
}- Centralize shared dependencies in
travel-sdk - Use exact versions for consistency
- Regular dependency audits
- Use
mprocsfor orchestrated development - Enable hot reloading for fast iterations
- Implement proper error boundaries
- Keep micro-frontends loosely coupled
- Share common UI through
travel-core - Use TypeScript for type safety
- Lazy load non-critical micro-frontends
- Optimize bundle sizes with tree shaking
- Use Hermes for production builds
- Module Federation V2 Documentation
- Re.Pack Documentation
- React Native New Architecture
- Nx Monorepo Guide
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ using Module Federation V2, Re.Pack 5.x, and React Native 0.79.5