Requires at least NativeScript CLI v8.x.x or higher. You can confirm your CLI version by running
ns --version.
npx create-nx-workspace@latest --cli=nx --preset=empty
// If you run into any issue with latest Nx workspace version you may want to try the last known stable version with the following:
npx [email protected] --cli=nx --preset=empty# Using npm
npm install --save-dev @nativescript/nx
# Using yarn
yarn add -D @nativescript/nxnpx nx g @nativescript/nx:app <app-name> [...options]This will generate:
apps/nativescript-<app-name>
The NativeScript Nx plugin will prefix apps by default to help distinguish them against other apps in your workspace for clarity.
You will be prompted to choose a framework when this flag is ommitted.
Use this option to explicitly choose a specific frontend framework integration app.
This setting will be saved with plugin settings the first time it's used to automatically choose this frontend framework integration for subsequent usages and with other generators without having to specify the flag again.
If you prefer you can also provide a flag to suffix instead:
npx nx g @nativescript/nx:app <app-name> --groupByNameThis will generate:
apps/<app-name>-nativescript
Android:
npx nx run <app-name>:androidiOS: (Mac only)
npx nx run <app-name>:iosA custom builder is provided via @nativescript/nx:build with the following options:
"debug": {
"type": "boolean",
"default": true,
"description": "Use 'ns debug' instead of 'ns run'. Defaults to true"
},
"device": {
"type": "string",
"description": "Device identifier to run app on.",
"alias": "d"
},
"emulator": {
"type": "boolean",
"default": false,
"description": "Explicitly run with an emulator or simulator"
},
"noHmr": {
"type": "boolean",
"default": false,
"description": "Disable HMR"
},
"uglify": {
"type": "boolean",
"default": false,
"description": "Enable uglify during the webpack build"
},
"verbose": {
"type": "boolean",
"default": false,
"description": "Enable verbose logging"
},
"release": {
"type": "boolean",
"default": false,
"description": "Enable release mode during build using the --release flag"
},
"forDevice": {
"type": "boolean",
"default": false,
"description": "Build in device mode using the --for-device flag"
},
"production": {
"type": "boolean",
"default": false,
"description": "Build in production mode using the --env.production flag"
}
The options follow the NativeScript command line options.
Here's an example app config:
"nativescript-mobile": {
"projectType": "application",
"root": "apps/nativescript-mobile/",
"sourceRoot": "apps/nativescript-mobile/src",
"prefix": "",
"targets": {
"build": {
"builder": "@nativescript/nx:build",
"options": {
"noHmr": true,
"production": true,
"uglify": true,
"release": true,
"forDevice": true
},
"configurations": {
"prod": {
"fileReplacements": [
{
"replace": "./src/environments/environment.ts",
"with": "./src/environments/environment.prod.ts"
}
]
}
}
},
"ios": {
"builder": "@nativescript/nx:build",
"options": {
"platform": "ios"
},
"configurations": {
"prod": {
"combineWithConfig": "build:prod"
}
}
},
"android": {
"builder": "@nativescript/nx:build",
"options": {
"platform": "android"
},
"configurations": {
"prod": {
"combineWithConfig": "build:prod"
}
}
},
"clean": {
"builder": "@nativescript/nx:build",
"options": {
"clean": true
}
}
}
}
Build with an environment configuration enabled (for example, with prod):
Android:
npx nx run <app-name>:android:prodiOS: (Mac only)
npx nx run <app-name>:ios:prodIt can be helpful to clean the app at times. This will clear out old dependencies plus iOS/Android platform files to give your app a nice reset.
npx nx run <app-name>:cleanYou can create a library of NativeScript components or plugins or whatever you'd like.
npx nx g @nativescript/nx:lib buttonsThis will generate a nativescript-buttons library where you could build out an entire suite of button behaviors and styles for your NativeScript apps.
import { PrimaryButton } from '@myorg/nativescript-buttons';The NativeScript Nx plugin will prefix libraries by default to help distinguish them against other apps and libraries in your workspace for clarity.
If you prefer you can also provide a flag to suffix instead:
npx nx g @nativescript/nx:lib buttons --groupByNameWhich would generate a buttons-nativescript library.
import { PrimaryButton } from '@myorg/buttons-nativescript';NativeScript plugins can be used in Nx workspaces in one of the two following methods:
If the plugin is needed by one app only, and not others, you can install it for the specific app:
cd apps/<app-name>
ns plugin add <plugin-name>Alternatively, you can install the plugins at the workspace (root), so it is accesible to all your workspace apps:
npm install --save <plugin-name>If a plugin contains platforms folder with native includes, the plugin must be added to app package.json at moment. NativeScript#17 (comment)
