One supports using Metro as the bundler for native builds, providing a more stable and battle-tested bundling experience. While the default Vite bundler for native is experimental, Metro mode offers production-ready stability by leveraging React Native's standard bundler.
Configure the native bundler to Metro in your vite.config.ts
:
vite.config.ts
When using Metro mode, only some of the Vite features are supported. One provides only a subset of Vite functionality in Metro mode to maintain compatibility and stability.
babel.config.js
and metro.config.js
.Only the following Vite features and configurations are supported in Metro mode for now:
import.meta.env
Built-in Constants Partially Supported
: supported but may not work as expected for web specific variables.import.meta.env
Env Variables Supported
tsconfig-paths
Partially Supported
: As one automatically configuresvite-tsconfig-paths
to support path mappings defined in tsconfig.json
for your project, the same applies to Metro mode. However, if you are using the vite-tsconfig-paths
plugin manually, the custom options you provide there will not be applied for Metro.By default, the Metro bundler is configured with Expo's defaults.
Like ordinary React Native apps, you can still configure Metro using standard configuration files:
babel.config.js
- Configure Babel transformations for your JavaScript/TypeScript code:
babel.config.js
metro.config.js
- Configure more advanced Metro bundler settings, such as resolver, transformations, or watcher options:
metro.config.js
These configuration files work exactly as they would in a standard React Native project, giving you full control over the bundling process.
Metro mode is designed for production stability, but it may not match the performance of Vite as it is not optimized for speed, and is using Babel instead of SWC for transformations. However, we observed that Metro mode somehow provides better memory efficiency.
Edit this page on GitHub.