|
1 | 1 | --- |
2 | | -title: Overview of the Nx Angular Plugin |
3 | | -description: The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. |
| 2 | +title: Angular Plugin for Nx |
| 3 | +description: Use @nx/angular to create, run, and maintain Angular applications and libraries in an Nx workspace. |
4 | 4 | keywords: [angular] |
5 | 5 | sidebar: |
6 | 6 | label: Introduction |
7 | 7 | order: 1 |
8 | 8 | filter: 'type:References' |
9 | 9 | --- |
10 | 10 |
|
11 | | -The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries |
12 | | -within an Nx workspace. It also enables using Angular Devkit builders and schematics in Nx workspaces. |
13 | | - |
14 | | -Among other things, it provides: |
15 | | - |
16 | | -- Integration with libraries such as: |
17 | | - - Cypress |
18 | | - - ESLint |
19 | | - - Jest |
20 | | - - Playwright |
21 | | - - Storybook |
22 | | -- Generators to help scaffold code quickly, including: |
23 | | - - Micro Frontends |
24 | | - - Libraries, both internal to your codebase and publishable to npm |
25 | | - - Projects with Tailwind CSS |
26 | | -- Executors providing extra capabilities on top of the Angular Devkit builders: |
27 | | - - Provide ESBuild plugins |
28 | | - - Provide custom webpack configurations |
29 | | -- Utilities for automatic workspace refactoring |
30 | | - |
31 | | -{% aside type="note" title="Currently using the Angular CLI?" %} |
32 | | -You can easily and mostly **automatically migrate from an Angular CLI** project to Nx! Learn |
33 | | -more [here](/docs/technologies/angular/migration/angular). |
34 | | -{% /aside %} |
| 11 | +[Angular](https://angular.dev) is a framework for building web applications. Nx has first party support for Angular projects. If you're familiar with the Angular CLI, `ng`, then Nx CLI will feel very familiar. |
| 12 | +The `@nx/angular` plugin adds [generators](#local-development), Angular CLI builder integration (executors) and migrations so you can run Angular tasks through Nx. With Nx, each project has its own configuration instead of a single `angular.json` file, making it more scalable for monorepos. |
| 13 | +You can use Angular with Nx without the plugin and still get [task caching](/docs/features/cache-task-results), [task orchestration](/docs/features/run-tasks), and the [project graph](/docs/features/explore-graph). |
35 | 14 |
|
36 | | -## Setting Up @nx/angular |
| 15 | +See the [Nx and Angular versions matrix](/docs/technologies/angular/guides/angular-nx-version-matrix) to know which Nx version supports a given Angular version. |
37 | 16 |
|
38 | | -### Installation |
| 17 | +## Setup |
39 | 18 |
|
40 | | -{% aside type="note" title="Keep Nx Package Versions In Sync" %} |
41 | | -Make sure to install the `@nx/angular` version that matches the version of `nx` in your repository. If the version numbers get out of sync, you can encounter some difficult to debug errors. You can [fix Nx version mismatches with this recipe](/docs/guides/tips-n-tricks/keep-nx-versions-in-sync). |
42 | | -{% /aside %} |
| 19 | +### Add to an existing workspace |
43 | 20 |
|
44 | | -In any Nx workspace, you can install `@nx/angular` by running the following command: |
| 21 | +{% aside type="note" title="Keep Nx package versions in sync" %} |
| 22 | +Install the `@nx/angular` version that matches your `nx` version to avoid hard-to-debug errors. See [Keep Nx versions in sync](/docs/guides/tips-n-tricks/keep-nx-versions-in-sync). |
| 23 | +Using `nx add` helps ensure the correct version is installed and configured. |
| 24 | +{% /aside %} |
45 | 25 |
|
46 | 26 | ```shell |
47 | 27 | nx add @nx/angular |
48 | 28 | ``` |
49 | 29 |
|
50 | | -This will install the correct version of `@nx/angular`. |
| 30 | +Verify the plugin is active by inspecting an Angular project: |
| 31 | + |
| 32 | +```shell |
| 33 | +nx show project <your-app-name> |
| 34 | +``` |
| 35 | + |
| 36 | +Look for `build`, `serve`, `test`, `lint`, or `e2e` targets generated from `angular.json`. |
| 37 | + |
| 38 | +### Create a new workspace |
51 | 39 |
|
52 | | -{% aside type="note" title="Angular Tutorial" %} |
53 | | -For a full tutorial experience, follow the [Angular Monorepo Tutorial](/docs/getting-started/tutorials/angular-monorepo-tutorial) |
| 40 | +```shell |
| 41 | +npx create-nx-workspace my-org --template=nrwl/angular-template |
| 42 | +``` |
| 43 | + |
| 44 | +{% aside type="tip" title="Angular Tutorial" %} |
| 45 | +For a guided walkthrough, follow the [Angular Monorepo Tutorial](/docs/getting-started/tutorials/angular-monorepo-tutorial). |
54 | 46 | {% /aside %} |
55 | 47 |
|
56 | | -## Using the Angular Plugin |
| 48 | +## Local Development |
| 49 | + |
| 50 | +### Generate an Angular Application |
| 51 | + |
| 52 | +```shell |
| 53 | +nx g @nx/angular:app apps/my-app |
| 54 | +``` |
| 55 | + |
| 56 | +By default, Nx configures ESLint for linting, Jest for unit tests, and Cypress for e2e tests. Read more of the options available for the application generator in the [Angular application generators reference](/docs/technologies/angular/generators#application). |
57 | 57 |
|
58 | | -### Generating an angular application |
| 58 | +```shell |
| 59 | +nx serve my-app |
| 60 | +nx build my-app |
| 61 | +nx test my-app |
| 62 | +nx lint my-app |
| 63 | +nx e2e my-app |
| 64 | +``` |
59 | 65 |
|
60 | | -It's straightforward to generate an Angular application: |
| 66 | +### Generate an Angular Library |
61 | 67 |
|
62 | 68 | ```shell |
63 | | -nx g @nx/angular:app apps/appName |
| 69 | +nx g @nx/angular:lib libs/my-lib |
64 | 70 | ``` |
65 | 71 |
|
66 | | -By default, the application will be generated with: |
| 72 | +By default, Nx configures ESLint for linting, Jest for unit tests. Read more of the options available for the application generator in the [angular library generators reference](/docs/technologies/angular/generators#library). |
67 | 73 |
|
68 | | -- ESLint as the linter. |
69 | | -- Jest as the unit test runner. |
70 | | -- Cypress as the E2E test runner. |
| 74 | +There are also generators for setting up common items inside your projects, such as components and services: |
71 | 75 |
|
72 | | -We can then serve, build, test, lint, and run e2e tests on the application with the following commands: |
| 76 | +```shell |
| 77 | +nx g @nx/angular:component libs/my-lib/src/lib/my-component |
| 78 | +nx g @nx/angular:service libs/my-lib/src/lib/my-service |
| 79 | +``` |
73 | 80 |
|
74 | 81 | ```shell |
75 | | -nx serve appName |
76 | | -nx build appName |
77 | | -nx test appName |
78 | | -nx lint appName |
79 | | -nx e2e appName |
| 82 | +nx test my-lib |
| 83 | +nx lint my-lib |
80 | 84 | ``` |
81 | 85 |
|
82 | | -### Generating an angular library |
| 86 | +### Buildable and Publishable Libraries |
83 | 87 |
|
84 | | -Generating an Angular library is very similar to generating an application: |
| 88 | +If you need libraries that build or publish, generate them with build output enabled and an import path. This creates build targets you can cache and run in CI. |
| 89 | +See [Set up incremental builds for Angular libraries](/docs/technologies/angular/guides/setup-incremental-builds-angular) for details. |
85 | 90 |
|
86 | 91 | ```shell |
87 | | -nx g @nx/angular:lib libs/libName |
| 92 | +nx g @nx/angular:lib libs/my-lib |
88 | 93 | ``` |
89 | 94 |
|
90 | | -By default, the library will be generated with: |
| 95 | +### Set Up Module Federation |
| 96 | + |
| 97 | +Nx includes generators for scaffolding [Module Federation](/docs/technologies/module-federation/concepts/module-federation-and-nx) architectures with Angular. Generate a host application and its remotes in one command: |
91 | 98 |
|
92 | | -- ESLint as the linter. |
93 | | -- Jest as the unit test runner. |
| 99 | +```shell |
| 100 | +nx g @nx/angular:host apps/shell --remotes=products,checkout |
| 101 | +``` |
94 | 102 |
|
95 | | -We can then test and lint the library with the following commands: |
| 103 | +> See all options in the [Angular host generators reference](/docs/technologies/angular/generators#host). |
| 104 | + |
| 105 | +Add a remote to an existing host: |
96 | 106 |
|
97 | 107 | ```shell |
98 | | -nx test libName |
99 | | -nx lint libName |
| 108 | +nx g @nx/angular:remote apps/login --host=shell |
100 | 109 | ``` |
101 | 110 |
|
102 | | -Read more about: |
| 111 | +> See all options in the [Angular remote generators reference](/docs/technologies/angular/generators#remote). |
103 | 112 |
|
104 | | -- [Creating Libraries](/docs/concepts/decisions/project-size) |
105 | | -- [Library Types](/docs/concepts/decisions/project-dependency-rules) |
106 | | -- [Buildable and Publishable Libraries](/docs/concepts/buildable-and-publishable-libraries) |
| 113 | +Pass `--dynamic` for [dynamic federation](/docs/technologies/angular/guides/dynamic-module-federation-with-angular) (remotes resolved at runtime) or `--ssr` for [server-side rendering with Module Federation](/docs/technologies/angular/guides/module-federation-with-ssr). |
107 | 114 |
|
108 | | -### Fallback to `@schematics/angular` |
| 115 | +## CI Considerations |
109 | 116 |
|
110 | | -If you try to invoke a generator that is not present in `@nx/angular`, the request will automatically be forwarded on |
111 | | -to `@schematics/angular`. So, even though there is no `@nx/angular:service` generator, the following command will |
112 | | -successfully create a service: |
| 117 | +Run only what changed using the project graph: |
113 | 118 |
|
114 | 119 | ```shell |
115 | | -nx g @nx/angular:service apps/appName/src/lib/my-service/my-service |
| 120 | +nx affected -t build test lint e2e |
116 | 121 | ``` |
117 | 122 |
|
118 | | -## More Documentation |
| 123 | +Enable remote caching for faster CI runs: |
| 124 | + |
| 125 | +```shell |
| 126 | +nx connect |
| 127 | +``` |
| 128 | + |
| 129 | +If you use Angular CLI configurations, define a `ci` configuration in `angular.json` and run tasks with `--configuration=ci` for CI-specific settings. |
| 130 | + |
| 131 | +See [Set Up CI](/docs/guides/nx-cloud/setup-ci) for a sample CI setup. |
| 132 | + |
| 133 | +## What's Next |
119 | 134 |
|
120 | | -- [Angular Monorepo Tutorial](/docs/getting-started/tutorials/angular-monorepo-tutorial) |
121 | | -- [Migrating from the Angular CLI](/docs/technologies/angular/migration/angular) |
122 | | -- [Setup Module Federation with Angular and Nx](/docs/technologies/module-federation/concepts/faster-builds-with-module-federation) |
123 | | -- [Using Tailwind CSS with Angular projects](/docs/technologies/angular/guides/using-tailwind-css-with-angular-projects) |
| 135 | +{% cardgrid %} |
| 136 | +{% linkcard title="Angular Monorepo Tutorial" description="Build an Angular monorepo step-by-step with Nx." href="/docs/getting-started/tutorials/angular-monorepo-tutorial" /%} |
| 137 | +{% linkcard title="Migrate from Angular CLI" description="Move an existing Angular CLI project into Nx." href="/docs/technologies/angular/migration/angular" /%} |
| 138 | +{% linkcard title="Dynamic Module Federation" description="Load Angular remotes at runtime with dynamic federation." href="/docs/technologies/angular/guides/dynamic-module-federation-with-angular" /%} |
| 139 | +{% linkcard title="Tailwind CSS with Angular" description="Add Tailwind CSS to Angular apps and libraries." href="/docs/technologies/angular/guides/using-tailwind-css-with-angular-projects" /%} |
| 140 | +{% linkcard title="Angular Generators Reference" description="All @nx/angular generators." href="/docs/technologies/angular/generators" /%} |
| 141 | +{% linkcard title="Angular Executors Reference" description="All @nx/angular executors." href="/docs/technologies/angular/executors" /%} |
| 142 | +{% /cardgrid %} |
0 commit comments