What is metro?
Metro is a JavaScript bundler for React Native, designed to be fast and scalable, handling the packaging of JavaScript code for React Native apps. It compiles and bundles your JavaScript code and assets into a single file, optimizing for performance and efficiency. Metro is the default bundler for React Native, but it can also be used for other JavaScript projects.
What are metro's main functionalities?
Code Bundling
Metro bundles your JavaScript code and assets into a single file. This process is initiated by running the React Native start command, which starts the Metro bundler. The bundler then compiles the JavaScript code, optimizes it, and packages it into a single file that can be executed by the React Native app.
npx react-native start
Fast Refresh
Metro supports Fast Refresh, a feature that allows developers to get instant feedback on their changes without losing the application state. Fast Refresh combines the benefits of hot reloading and full reloading, providing a seamless development experience.
n/a
Asset Management
Metro handles the packaging and optimization of assets (such as images and fonts) alongside JavaScript code. It ensures that assets are bundled and loaded efficiently in the React Native app.
n/a
Other packages similar to metro
webpack
Webpack is a powerful module bundler for JavaScript applications, capable of transforming, bundling, or packaging just about any resource or asset. While Metro is optimized for React Native, Webpack is more flexible and can be used with a variety of frameworks and libraries. Webpack offers a rich plugin ecosystem and extensive configuration options, making it suitable for complex web application development.
parcel
Parcel is a web application bundler that offers out-of-the-box support for many file types without the need for configuration. It's designed to be fast, utilizing multicore processing to efficiently handle asset bundling. Compared to Metro, Parcel is more general-purpose, targeting web development rather than being optimized for React Native. Parcel's zero-configuration approach makes it appealing for projects where simplicity and speed are priorities.
rollup
Rollup is a module bundler for JavaScript that compiles small pieces of code into something larger and more complex, such as a library or application. It's known for its efficiency and is often used for bundling JavaScript libraries. Rollup focuses on producing smaller bundles by eliminating unused code. While Metro is tailored for React Native apps, Rollup is more suited for library development and projects where bundle size is a critical concern.
Metro
π The JavaScript bundler for React Native.
- π
Fast: We aim for sub-second reload cycles, fast startup and quick bundling speeds.
- βοΈ Scalable: Works with thousands of modules in a single application.
- βοΈ Integrated: Supports every React Native project out of the box.
This project was previously part of the react-native repository. In this smaller repository it is easier for the team working on Metro to respond to both issues and pull requests. See react-native#13976 for the initial announcement.