0%

nx commands

Generate app

Take Angular as an example, first, install angular plugin for Nx.

1
nx add @nx/angular

Then, generate an app.

1
nx g @nx/angular:app appName

Generate library

1
nx g @nx/angular:lib libName

Generate Angular component

The following command generate a angular component for project my-app.

1
nx generate @nx/angular:component my-component --project=my-app

Note that --project is deprecated and will be removed in Nx v20, use --directory instead.

1
nx generate @nx/angular:component my-component --directory=apps/my-app/src/app

The value of --directory is relative to the root of the project.

Note –directory is only used for component, to generate service in Angular, you can still use --project.

If above commands not work, use the following command. where header is the name of the component, the first one is folder name.

1
nx generate @nx/angular:component apps/yanzhenqingshufa/src/app/layout/header/header

Show affected apps

nx v15

1
nx affected:apps

nx v16

1
nx print-affected --type=app --select=projects

nx v17+

1
2
3
nx show projects --affected
nx affected --graph -t build
nx graph --affected

If there is no affected apps, nx print-affected will show the following output. look at the projects property, its empty, which means there is no affected apps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"tasks": [],
"projects": [],
"projectGraph": {
"nodes": [
"content-templates",
"todos-e2e",
"todos",
"data",
"api",
"ui"
],
}
}

If your apps/libs was created manually, you have to make sure that there is a file project.json under the root of your app/lib, and have the following content at least.

1
2
3
4
{
"name": "content-templates",
"projectType": "application"
}

Show graph

1
nx dep-graph