0.1.2 ā€¢ Published 12 months ago

@xtreamsrl/react-native-incremental-cli v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

React Native Incremental CLI

The native build of a React Native project is the slowest part of the build process. It's an expensive operation, especially compared with the JS bundle, and it's not uncommon for it to take 5-10 minutes to complete. But most of the time the native build is not necessary. For example, if you are only changing the JavaScript code (and when you app reaches a stable point this is the most common situation), there is no need to rebuild the native code. This is where this CLI tool comes in. This project is a meant as drop in replacement fo the react-native CLI tool that caches the native build and only rebuilds it when necessary. This can save a lot of time during development.

The release is even more expensive than the debug build. Thi cli tool can also cache the release build and only repack it with the new JS bundle.

For now, the developers should choose if the native build should be forced or not. In the future, the cli tool may add some heuristics to decide when to force the native build.

Run android with build cached

Disclaimer

There are many configurations for native builds, and it's possible that this CLI does not support your specific configuration. If you encounter any issues, please feel free to file an issue or submit a pull request.

Credits

This project is highly inspired by the React Native architecture articles by Wix and the related repo.

Requirements

For more detailed information on setting up your development environment for Android and iOS, refer to the official React Native documentation.

Android

  • Java Development Kit
  • Android Studio
  • Android SDK
  • Environment variables
    • JAVA_HOME
    • ANDROID_HOME
    • ANDROID_SDK_ROOT

iOS

  • A macOS machine with Xcode.
  • CocoaPods.
  • Xcode command line tools

Installation

npm install --save-dev @xtream/react-native-incremental-cli

Usage

Run

The run command launches the app on the emulator. It will first check if the native build is present in the cache folder. If it is, it will use it. If it is not, it will build it and then run the app.

The target device can be selected directly from the command line.

The cli handles also metro bundler. If it is not running, it will start it.

npx rn-incremental run [-a|-i] [-f|--flavor flavor] [--force-build]

Options

  • -i/--ios: run on iOS
  • -a/--android: run on Android
  • -f/--flavor: specify the flavor/schema
  • --force-build: force a native build

Build

The build command builds the app for the specified platform. It's an explicit build, so it will override the cache folder for the specified platform and flavor/scheme, unless the --incremental option is used.

rn-incremental build [-i/--ios] [-a/--android] [-f/--flavor] [--release] [-I/--incremental] [--force-build]

Options

  • -i/--ios: build for iOS
  • -a/--android: build for Android
  • -f/--flavor: specify the flavor/schema
  • --release: build a release version
  • -I/--incremental: build an incremental version

Supported features and platforms

The cli supports macOS for now. Windows support is coming soon for android.

āœ… - Supported, šŸš§ - In progress, āŒ - Not supported

FeatureAndroidiOS
Run on emulatorāœ…āœ…
Run on devicešŸš§šŸš§
Debug buildāœ…āœ…
Build flavor/schemaāœ…āœ…
Release buildāœ…šŸš§
Incremental buildšŸš§šŸš§
Resign of incremental buildšŸš§šŸš§
Re-versioning of incremental buildsšŸš§šŸš§

How it works

Cache folder

The CLI creates a .rn-incremental folder in the root of the project that is used as cache for the native builds. This is what makes the builds so fast, as it reuses the native build if it is present while running a project. You can force a rebuild with the --force-build option.

Incremental builds

Incremental builds are a way to speed up the release build. The idea is to reuse the native build of a previous release and only repack it with the new JS bundle and assets.

It just executes the following steps:

  • extract the native build from the previous release
  • rebuild JS bundle and assets
  • repack the native build with the new JS bundle and assets
  • resign the app if necessary

Who we are