NX commands
A subset of nx cli commands
Global Options:
1
--dry-run
2
--buildable # options for libs. alias is: publishable
3
--tags=
4
domain: <shared>
5
type: <app/util/ui/feature/domain-logic/shell>
6
platform: <web/mobile/desktop/node/universal>
Copied!

Generate Commands

Generate Modules

buildable is alias for old publishable you can always make an existing library buildable after the fact.
Every buildable library has a build task.
1
yarn create nx-workspace yeti --preset=empty -prefix=yeti # create an empty workspace
2
nx g @nrwl/angular:app yeti-web-app --style=scss --prefix=yeti --routing --tags="domain:yeti,type:app,platform:web" --dry-run
3
nx g @nrwl/nest:app yeti-api --frontendProject=yeti-web-app --tags="domain:yeti,type:api,platform:node"
4
5
# generate share angular lib module
6
nx g @nrwl/angular:lib ui --style=scss --tags="domain:shared,type:ui,platform:web"
7
nx g @nrwl/angular:lib knob --directory=components --buildable --style=scss --tags="domain:shared,type:ui,platform:web"
8
nx g @nrwl/nest:lib <nest-lib> [--controller] [--service] [--global] [--buildable] [--tags] # generate nestjs lib module
9
nx g @nrwl/workspace:lib btree --directory=utils --tags="domain:shared,type:util,platform:universal" # generate share universal lib module
Copied!

Refactor Modules

1
# Move libs/my-feature-lib to libs/shared/my-feature-lib
2
nx g @nrwl/workspace:move --project my-feature-lib shared/my-feature-lib
3
nx g @nrwl/workspace:move --project api yeti-api
4
# Remove my-feature-lib from the workspace:
5
nx g @nrwl/workspace:remove my-feature-lib --dry-run
6
# Force removal of my-feature-lib from the workspace:
7
nx g @nrwl/workspace:remove my-feature-lib --forceRemove
Copied!

Generate Components

1
nx g component todos --project=ui --export # add a component to the newly created ui library
Copied!

Generate workspace schematics

1
# Generates a workspace schematic
2
nx g @nrwl/workspace:workspace-schematic name --dry-run
Copied!

Run commands

For Single Project

1
# Long form
2
nx run todos:serve # default configuration
3
nx run todos:serve:production # producttion configuration
4
nx run todos:build
5
nx run todos:lint
6
nx run todos:e2e
7
nx run todos:test
8
nx run todos:generate-docs # run any custom command with `@nrwl/workspace:run-commands`
9
# short form
10
nx serve todos
11
nx serve todos --configuration=production
12
nx serve todos --prod
13
nx build todos
14
nx build todos --with-deps # same as `nx run-many --target=build --projects=todos --with-deps`
15
nx lint todos
16
nx e2e todos
17
nx test todos
Copied!

For Multiple Projects

1
nx run-many --target=build --all # Run the same target for all projects.
2
nx run-many --target=build --all --parallel --maxParallel=8 # Run the same target for all projects in parallel.
3
nx run-many --target=build --projects=app1,app2 # Run the same target for selected projects.
4
nx run-many --target=build --projects=app1,app2 --with-deps # Run the same target for selected projects and their deps.
5
nx run-many --target=build --all --only-failed # Run the same target for the projects that failed last time.
6
nx run-many --target=build --all --prod # Any flags you pass to run-many that aren't Nx specific will be passed down to the builder.
Copied!

For Affected Projects

The print-affected and run-many commands can be used to set up your CI to use multiple agents, while still rebuilding and retesting only what is affected.
1
nx affected --target=build # Run the same target for all the projects by the current code change (e.g., current Git branch).
2
nx affected --target=build --parallel --maxParallel=8 # Same but in parallel.
3
# By default, the current code change is defined as a diff between master and HEAD. You can change it as follows:
4
nx affected --target=build --parallel --maxParallel=8 --base=origin/development --head=$CI_BRANCH_NAME
5
# Running affected commands is very common, so Nx comes with a few shortcuts.
6
nx affected:build
7
nx affected:test
8
nx affected:lint
9
nx affected:e2e
10
# Any flags you pass to run-many that aren't Nx specific will be passed down to the builder.
11
nx affected --target=build --prod
Copied!

Other Commands

1
nx print-affected
2
nx dep-graph
3
nx affected:dep-graph
4
nx list # lists all installed and available plugins.
5
nx list @xmlking/nxp-ddd # see details of a plugin
6
nx report # prints basic information about the plugins used
7
# format code
8
nx format:check
9
nx format:write
10
# migrate
11
nx migrate
12
nx migrate next
13
nx migrate @nrwl/[email protected] --from="@nrwl/[email protected],@nrwl/[email protected]"
14
nx migrate @nrwl/[email protected] --to="@nrwl/[email protected],@nrwl/[email protected]"
15
# Lint workspace or list of files
16
nx workspace-lint
Copied!

Reference

Last modified 9mo ago