Linux command
metro 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Start Metro bundler
npx react-native start
Start with cache reset
npx react-native start --reset-cache
Start on specific port
npx react-native start --port [8082]
Bundle for production
npx react-native bundle --platform [android] --dev false --entry-file [index.js] --bundle-output [bundle.js]
Enable verbose logging
npx react-native start --verbose
说明
Metro is the JavaScript bundler used by React Native. It compiles and bundles JavaScript code and assets, handles module resolution, and provides hot reloading during development. Metro is optimized for React Native's requirements with fast incremental builds.
参数
- --port _port_
- Server port.
- --reset-cache
- Clear bundler cache.
- --verbose
- Verbose output.
- --config _file_
- Config file path.
- --entry-file _file_
- Entry point file.
- --bundle-output _file_
- Output bundle file.
- --platform _platform_
- Target platform (ios, android).
- --dev _boolean_
- Development mode flag for the bundle (default: true).
- --host _host_
- Host to listen on (default: localhost).
- --max-workers _N_
- Specify the maximum number of workers for parallelization.
FAQ
What is the metro command used for?
Metro is the JavaScript bundler used by React Native. It compiles and bundles JavaScript code and assets, handles module resolution, and provides hot reloading during development. Metro is optimized for React Native's requirements with fast incremental builds.
How do I run a basic metro example?
Run `npx react-native start` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --port _port_ do in metro?
Server port.