Skip to content

The @nx/react-native plugin provides various executors to help you create and configure react-native projects within your Nx workspace. Below is a complete reference for all available executors and their options.

build-android

Build target options for Android.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"build-android": {
"executor": "@nx/react-native:build-android",
"outputs": [
"{projectRoot}/build/outputs/bundle",
"{projectRoot}/build/outputs/apk"
],
"options": {}
}
}
}
Terminal window
nx run mobile:build-android

Examples

{% tabs %} {% tab label=“Build with custom tasks” %} The tasks option accepts any custom gradle task, such as assembleDebug, assembleRelease, bundleDebug, bundleRelease, installDebug, installRelease. For example, pass in bundleRelease or bundleRelease to tasks, it will create with .aab extension under bundle folder. Pass in assembleDebug or assembleRelease to tasks, it will create a build with .apk extension under apk folder. Pass in installDebug or installRelease to tasks, it will create a build with .apk extension and immediately install it on a running emulator or connected device.

"build-android": {
"executor": "@nx/react-native:build-android",
"outputs": [
"{projectRoot}/build/outputs/bundle",
"{projectRoot}/build/outputs/apk"
],
"options": {
"tasks": ["bundleRelease"]
}
}

{% /tab %} {% tab label=“Build for debug/release” %}

The mode option allows you determine whether to build for debug/release apk.

"build-android": {
"executor": "@nx/react-native:build-android",
"outputs": [
"{projectRoot}/build/outputs/bundle",
"{projectRoot}/build/outputs/apk"
],
"options": {
"mode": "debug"
}
}

{% /tab %} {% tab label=“Build for current device architecture” %}

The activeArchOnly option allows you to build native libraries only for the current device architecture for debug builds.

"build-android": {
"executor": "@nx/react-native:build-android",
"outputs": [
"{projectRoot}/build/outputs/bundle",
"{projectRoot}/build/outputs/apk"
],
"options": {
"activeArchOnly": true
}
}

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
activeArchOnlybooleanBuild native libraries only for the current device architecture for debug builds.false
extraParamsstringCustom params passed to gradle build command
interactivebooleanExplicitly select build type and flavour to use before running a build
modestringSpecify your app’s build variant"debug"
portnumberThe port where the packager server is listening on.8081
resetCachebooleanResets metro cache.false
tasksstringRun custom Gradle tasks. By default it’s “assembleDebug”. Will override passed mode and variant arguments.

build-ios

Build iOS app.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {}
}
}
}
Terminal window
nx run mobile:build-ios

Examples

{% tabs %} {% tab label=“Build in Specific Location” %} The buildFolder option allows to specify the location for ios build artifacts. It corresponds to Xcode’s -derivedDataPath.

"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {
"buildFolder": "dist/ios/build"
}
}
Terminal window
nx build-ios <app-name> --buildFolder=dist/ios/build

{% /tab %} {% tab label=“Build the Debug/Release app” %} The mode option allows to specify the xcode configuartion, such as Debug or Release.

"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {
"mode": "Release"
}
}
Terminal window
nx build-ios <app-name> --mode=Debug
nx build-ios <app-name> --mode=Release

{% /tab %} {% tab label=“Build for a simulator” %} The simulator option allows you to launch your iOS app in a specific simulator:

To see all the available simulators, run command:

Terminal window
xcrun simctl list devices available
"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {
"simulator": "iPhone 14 Pro"
}
}
Terminal window
nx build-ios <app-name> --simulator="iPhone 14 Pro"

{% /tab %} {% tab label=“Build for a device” %} The device option allows you to launch your iOS app in a specific device.

To see all the available device, run command:

Terminal window
xcrun simctl list devices available
"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {
"device": "deviceName"
}
}
Terminal window
nx build-ios <app-name> --device="deviceName"

{% /tab %} {% tab label=“Set Device by udid” %} The udid option allows you to explicitly set device to use by udid.

To see all the available simulators and devices with udid, run command:

Terminal window
xcrun simctl list devices available
"build-ios": {
"executor": "@nx/react-native:build-ios",
"options": {
"udid": "device udid"
}
}
Terminal window
nx build-ios <app-name> --udid="device udid"

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
buildFolderstringLocation for iOS build artifacts. Corresponds to Xcode’s “-derivedDataPath”. Relative to ios directory"./build"
devicestringExplicitly set device to use by name. The value is not required if you have a single device connected.
extraParamsstringCustom params that will be passed to xcodebuild command.
interactivebooleanExplicitly select which scheme and configuration to use before running a build
modestringExplicitly set the scheme configuration to use"Debug"
portnumberThe port where the packager server is listening on.8081
resetCachebooleanResets metro cache.false
schemestringExplicitly set Xcode scheme to use
simulatorstringExplicitly set simulator to use. Optionally include iOS version between parenthesis at the end to match an exact version: “iPhone 6 (10.0)“
udidstringExplicitly set device to use by udid
verbosebooleanDo not use xcbeautify or xcpretty even if installed
xcconfigstringExplicitly set xcconfig to use

bundle

JS Bundle target options.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"bundle-ios": {
"executor": "@nx/react-native:bundle",
"outputs": ["{projectRoot}/build"],
"options": {
"entryFile": "src/main.tsx",
"platform": "ios",
"bundleOutput": "dist/apps/mobile/ios/main.jsbundle"
}
},
"bundle-android": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "android",
"bundleOutput": "dist/apps/mobile/android/main.jsbundle"
}
}
}
}
Terminal window
nx run mobile:bundle-ios
nx run mobile:bundle-android

Examples

{% tabs %} {% tab label=“Bundle with sourcemap” %} The sourcemapOutput option allows you to specify the path of the source map relative to app folder:

"bundle-ios": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "ios",
"bundleOutput": "dist/apps/mobile/ios/main.jsbundle",
"sourcemapOutput": "../../dist/apps/mobile/ios/main.map",
}
},
"bundle-android": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "android",
"bundleOutput": "dist/apps/mobile/android/main.jsbundle",
"sourcemapOutput": "../../dist/apps/mobile/android/main.map",
}
}

{% /tab %} {% tab label=“Create a dev/release bundle” %}

The dev option determines whether to create a dev or release bundle. The default value is true, by setting it as false, warnings are disabled and the bundle is minified.

"bundle-ios": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "ios",
"bundleOutput": "dist/apps/mobile/ios/main.jsbundle",
"dev": false
}
},
"bundle-android": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "android",
"bundleOutput": "dist/apps/mobile/android/main.jsbundle",
"dev": false
}
}

{% /tab %} {% tab label=“Create a minified bundle” %}

The minify option allows you to create a minified bundle:

"bundle-ios": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "ios",
"bundleOutput": "dist/apps/mobile/ios/main.jsbundle",
"minify": true
}
},
"bundle-android": {
"executor": "@nx/react-native:bundle",
"options": {
"entryFile": "src/main.tsx",
"platform": "android",
"bundleOutput": "dist/apps/mobile/android/main.jsbundle",
"minify": true
}
}

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
bundleOutputstring [required]The output path of the generated files.
entryFilestring [required]The entry file relative to project root.
platformany [required]Platform to build for.
assetsDeststringDirectory name where to store assets referenced in the bundle.
devbooleanGenerate a development build.true
maxWorkersnumberThe number of workers we should parallelize the transformer on.
minifybooleanAllows overriding whether bundle is minified.
readGlobalCachebooleanTry to fetch transformed JS code from the global cache, if configured.false
resetCachebooleanRemoves cached files.false
sourcemapOutputstringFile name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map.
sourcemapSourcesRootstringPath to make sourcemaps sources entries relative to, ex. /root/dir.
sourcemapUseAbsolutePathbooleanReport SourceMapURL using its full path.false
transformerstringSpecify a custom transformer to be used.

Ensure workspace node_modules is symlink under app’s node_modules folder.

pod-install

Run pod install for React Native iOS Project.

Options

OptionTypeDescriptionDefault
buildFolderstring [required]Location for iOS build artifacts. Corresponds to Xcode’s “-derivedDataPath”. Relative to ios directory."./build"
deploymentbooleanDisallow any changes to the Podfile or the Podfile.lock during installation.false
repoUpdatebooleanForce running pod repo update before install.false
useBundlerbooleanRun cocoapods within a Bundler environment, i.e. with the bundle exec pod install commandfalse

run-android

Run Android target options.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"run-android": {
"executor": "@nx/react-native:run-android",
"options": {}
}
}
}
Terminal window
nx run mobile:run-android

Examples

{% tabs %} {% tab label=“Run on a specific device/simulator” %} To see all the available emulators, run command:

Terminal window
emulator -list-avds

The deviceId option allows you to launch your android app in a specific device/simulator:

"run-android": {
"executor": "@nx/react-native:run-android",
"options": {
"deviceId": "Pixel_5_API_30"
}
}

{% /tab %} {% tab label=“Run the debug/release app” %} The mode option allows to specify the build variant, such as debug or release.

"run-android": {
"executor": "@nx/react-native:run-android",
"options": {
"mode": "release"
}
}

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
activeArchOnlybooleanBuild native libraries only for the current device architecture for debug builds.false
appIdstringSpecify an applicationId to launch after build. If not specified, package from AndroidManifest.xml will be used.
appIdSuffixstringSpecify an applicationIdSuffix to launch after build.
binaryPathstringPath relative to project root where pre-built .apk binary lives.
deviceIdstringBuilds your app and starts it on a specific device/simulator with the given device id (listed by running adb devices on the command line).
extraParamsstringCustom params passed to gradle build command
interactivebooleanExplicitly select build type and flavour to use before running a build
listDevicesbooleanLists all available Android devices and simulators and let you choose one to run the app
mainActivitystringName of the activity to start."MainActivity"
modestringSpecify your app’s build variant"debug"
portnumberThe port where the packager server is listening on.8081
resetCachebooleanResets metro cache.false
tasksstringRun custom Gradle tasks. By default it’s “assembleDebug”. Will override passed mode and variant arguments.

run-ios

Run iOS target options.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"run-ios": {
"executor": "@nx/react-native:run-ios",
"options": {}
}
}
}
Terminal window
nx run mobile:run-ios

Examples

{% tabs %} {% tab label=“Build the Debug/Release app” %} The mode option allows to specify the xcode configuartion schema, such as Debug or Release.

"run-ios": {
"executor": "@nx/react-native:run-ios",
"options": {
"mode": "Release"
}
}
Terminal window
nx run-ios <app-name> --mode=Debug

{% /tab %} {% tab label=“Run on a simulator” %} The simulator option allows you to launch your iOS app in a specific simulator.

To see all the available simulators, run command:

Terminal window
xcrun simctl list devices available
"run-ios": {
"executor": "@nx/react-native:run-ios",
"options": {
"simulator": "iPhone 14 Pro (16.2)"
}
}
Terminal window
nx run-ios <app-name> --simulator="iPhone 14 Pro (16.2)"

{% /tab %} {% tab label=“Run on a device” %} The device option allows you to launch your iOS app in a specific device.

To see all the available devices, run command:

Terminal window
xcrun simctl list devices available
"run-ios": {
"executor": "@nx/react-native:run-ios",
"options": {
"device": "deviceName"
}
}
Terminal window
nx run-ios <app-name> --device="deviceName"

{% /tab %} {% tab label=“Set Device by udid” %} The udid option allows you to explicitly set device to use by udid.

To see all the available simulators and devices with udid, run command:

Terminal window
xcrun simctl list devices available
"run-ios": {
"executor": "@nx/react-native:run-ios",
"options": {
"udid": "device udid"
}
}
Terminal window
nx run-ios <app-name> --udid="device udid"

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
binaryPathstringPath relative to project root where pre-built .app binary lives.
buildFolderstringLocation for iOS build artifacts. Corresponds to Xcode’s “-derivedDataPath”. Relative to ios directory.
devicestringExplicitly set device to use by name. The value is not required if you have a single device connected.
extraParamsstringCustom params that will be passed to xcodebuild command.
interactivebooleanExplicitly select which scheme and configuration to use before running a build
modestringExplicitly set the scheme configuration to use"Debug"
portnumberThe port where the packager server is listening on.8081
resetCachebooleanResets metro cache.false
schemestringExplicitly set Xcode scheme to use
simulatorstringExplicitly set simulator to use. Optionally include iOS version between parenthesis at the end to match an exact version: “iPhone 6 (10.0)“
udidstringExplicitly set device to use by udid
verbosebooleanDo not use xcbeautify or xcpretty even if installed
xcconfigstringExplicitly set xcconfig to use

start

Packager Server target options.

project.json:

{
"name": "mobile",
//...
"targets": {
//...
"start": {
"executor": "@nx/react-native:start",
"options": {
"port": 8081
}
}
}
}
Terminal window
nx run mobile:start

Examples

{% tabs %} {% tab label=“Starts the server non-interactively” %} The interactive option allows you to specify whether to use interactive mode:

"start": {
"executor": "@nx/react-native:start",
"options": {
"port": 8081,
"interactive": false
}
}

{% /tab %} {% tab label=“Starts the server with cache reset” %}

The resetCache option allows you to remove cached files.

"start": {
"executor": "@nx/react-native:start",
"options": {
"port": 8081,
"resetCache": true
}
}

{% /tab %} {% /tabs %}


Options

OptionTypeDescriptionDefault
interactivebooleanRun packager server in interactive mode.true
portnumberThe port to listen on.8081
resetCachebooleanResets metro cache.false

storybook

Load stories for react native.

Options

OptionTypeDescriptionDefault
outputFilestring [required]The output file that will be written. It is relative to the project directory."./.storybook/story-loader.ts"
patternstring [required]The pattern of files to look at. It can be a specific file, or any valid glob. Note: if using the CLI, globs with **/*... must be escaped with quotes`”**/*.stories.@(js
searchDirarray [required]The directory or directories, relative to the project root, to search for files in.[]

sync-deps

Updates package.json with project dependencies.

Options

OptionTypeDescriptionDefault
allbooleanCopy all dependencies and devDependencies from the workspace root package.json.false
excludearrayAn array of npm packages to exclude.[]
includearrayAn array of additional npm packages to include.[]

upgrade

Upgrade React Native code for project.