react-native
Create and manage React Native projects
TLDR
Initialize a new React Native project in a directory of the same name
Start the metro bundler
Start the metro bundler with a clean cache
Build the current application and start it on a connected Android device or emulator
Build the current application and start it on an iOS simulator
Build the current application in release mode and start it on a connected Android device or emulator
Start logkitty and print logs to stdout
Start tail system.log for an iOS simulator and print logs to stdout
SYNOPSIS
react-native <command> [options] [arguments]
Examples:
react-native init MyProjectName
react-native run-android
react-native start
PARAMETERS
init <ProjectName>
Initializes a new React Native project in a directory named <ProjectName>, setting up the basic file structure and dependencies.
run-android
Builds and launches the React Native application on an attached Android device or a running Android emulator.
run-ios
Builds and launches the React Native application on an attached iOS device or a running iOS simulator (requires macOS and Xcode).
start
Starts the Metro JavaScript bundler and development server, which serves your JavaScript bundle to the device during development.
bundle
Bundles the JavaScript code and assets into a single file for release builds, typically used for production deployment.
log-android
Prints logs from the Android device or emulator, useful for debugging.
log-ios
Prints logs from the iOS simulator or device (requires macOS), useful for debugging.
--version
Displays the installed version of the React Native CLI.
--help
Provides help information for the main CLI command or a specific subcommand when used as react-native <command> --help.
DESCRIPTION
React Native is an open-source UI software framework created by Meta Platforms, Inc. It enables developers to build robust, high-performance mobile applications for Android and iOS platforms using JavaScript and the React library. Unlike traditional hybrid frameworks, React Native compiles JavaScript components into native UI components, offering a truly native look, feel, and performance. The react-native command-line interface (CLI) serves as the indispensable toolkit for developers working with React Native projects. It streamlines the entire development lifecycle, from initializing new project structures with necessary configurations and dependencies to running applications on various emulators, simulators, or physical devices. Furthermore, the CLI handles crucial tasks like bundling JavaScript code and static assets into production-ready packages and managing development servers for real-time code changes. It significantly simplifies the process of creating cross-platform mobile applications by abstracting away many platform-specific build complexities, allowing developers to write and maintain a single, efficient codebase that achieves native capabilities on both major mobile operating systems.
CAVEATS
The react-native command is not a core Linux utility but a JavaScript application CLI. It requires Node.js and a package manager like npm or yarn to be installed. Building for Android necessitates a Java Development Kit (JDK) and Android SDK, usually managed via Android Studio. For iOS development, a macOS environment with Xcode and its command-line tools is mandatory. Setting up the complete development environment can be complex and platform-specific.
METRO BUNDLER INTEGRATION
The react-native CLI tightly integrates with Metro Bundler, a JavaScript bundler optimized for React Native. Metro's primary role is to compile, optimize, and serve your application's JavaScript code and assets to the devices, enabling features like Fast Refresh and Hot Module Replacement during development, and generating production bundles.
NATIVE MODULES AND BRIDGING
A key strength of React Native, facilitated by its CLI, is its ability to interact with native platform features through 'native modules'. These modules allow JavaScript code to call platform-specific APIs (e.g., camera, GPS) and vice-versa, leveraging the native bridging mechanism. The CLI helps in linking and managing these native dependencies, although newer versions automate much of this process.
HISTORY
React Native was open-sourced by Facebook (now Meta) in March 2015, stemming from an internal hackathon project focused on enabling developers to build native UIs using JavaScript. Initially, it provided support exclusively for iOS, with Android support being integrated and released in September 2015. Over the years, the CLI has undergone significant enhancements, including improvements in dependency management (e.g., auto-linking native modules), performance, and developer experience. It has become a cornerstone for cross-platform mobile development, continuously evolving through substantial contributions from Meta and a vibrant open-source community.