2016-12-15 19:19:21 +00:00
# Building and Testing Angular
2015-03-18 01:48:02 +00:00
2016-12-15 19:19:21 +00:00
This document describes how to set up your development environment to build and test Angular.
2025-07-31 15:17:27 +00:00
It also explains the basic mechanics of using `git` , `node` , and `pnpm` .
2015-03-18 01:48:02 +00:00
2025-09-13 18:13:37 +00:00
- [Building and Testing Angular ](#building-and-testing-angular )
- [Prerequisite Software ](#prerequisite-software )
2025-12-30 08:18:13 +00:00
- [Development in a Container ](#development-in-a-container )
2026-04-02 03:17:57 +00:00
- [Experimenting in dev-app ](#experimenting-in-dev-app )
2025-09-13 18:13:37 +00:00
- [Getting the Sources ](#getting-the-sources )
- [Installing NPM Modules ](#installing-npm-modules )
- [Building ](#building )
- [Running Tests Locally ](#running-tests-locally )
- [Testing changes against a local library/project ](#testing-changes-against-a-local-libraryproject )
- [Building and serving a project ](#building-and-serving-a-project )
- [Cache ](#cache )
- [Invoking the Angular CLI ](#invoking-the-angular-cli )
- [Formatting your source code ](#formatting-your-source-code )
- [Linting/verifying your Source Code ](#lintingverifying-your-source-code )
- [Publishing Snapshot Builds ](#publishing-snapshot-builds )
- [Publishing to GitHub Repos ](#publishing-to-github-repos )
- [Bazel Support ](#bazel-support )
- [IDEs ](#ides )
- [VS Code ](#vs-code )
- [WebStorm / IntelliJ ](#webstorm--intellij )
- [Remote Build Execution and Remote Caching ](#remote-build-execution-and-remote-caching )
- [--config=remote flag ](#--configremote-flag )
2015-04-09 16:33:10 +00:00
2022-05-03 18:34:54 +00:00
See the [contribution guidelines ](https://github.com/angular/angular/blob/main/CONTRIBUTING.md )
2015-04-09 16:33:10 +00:00
if you'd like to contribute to Angular.
2015-03-18 01:48:02 +00:00
## Prerequisite Software
Before you can build and test Angular, you must install and configure the
2024-05-28 23:15:16 +00:00
following on your development machine:
2015-03-18 01:48:02 +00:00
2025-11-06 18:03:05 +00:00
- [Git ](https://git-scm.com/ ) and/or the [**GitHub app** ](https://desktop.github.com/ ) (for Mac and
2024-05-28 23:15:16 +00:00
Windows);
[GitHub's Guide to Installing Git ](https://help.github.com/articles/set-up-git ) is a good source
of information.\
2022-08-04 06:58:40 +00:00
**Windows Users** : Git Bash or an equivalent shell is required\
2025-11-06 18:03:05 +00:00
_Windows Powershell and cmd shells are not
supported [#46780 ](https://github.com/angular/angular/issues/46780 ) so some commands might fail_
2016-01-21 21:30:03 +00:00
2025-11-06 18:03:05 +00:00
- [Node.js ](https://nodejs.org ), (version specified in [`.nvmrc` ](../.nvmrc )) which is used to run a
2024-05-28 23:15:16 +00:00
development web server,
2025-09-13 18:13:37 +00:00
run tests, and generate distributable files.
2024-05-28 23:15:16 +00:00
`.nvmrc` is read by [nvm ](https://github.com/nvm-sh/nvm ) commands like `nvm install`
and `nvm use` .
2016-01-21 21:30:03 +00:00
2025-11-06 18:03:05 +00:00
- [pnpm ](https://pnpm.io/ ) (version specified in the engines field
2024-05-28 23:15:16 +00:00
of [`package.json` ](../package.json )) which is used to install dependencies.
2017-09-21 13:39:43 +00:00
2025-11-06 18:03:05 +00:00
- On Windows: [MSYS2 ](https://www.msys2.org/ ) which is used by Bazel. Follow
2024-05-28 23:15:16 +00:00
the [instructions ](https://bazel.build/install/windows#installing-compilers-and-language-runtimes )
2015-03-18 01:48:02 +00:00
2025-12-30 08:18:13 +00:00
## Development in a Container
You can also use the provided [Dev Container ](https://containers.dev/ ) configuration to set up a development environment. This approach uses Docker to create a container with all the necessary tools (Node.js, pnpm, etc.) pre-installed.
2026-04-02 03:17:57 +00:00
## Experimenting in dev-app
For experimentation while developing Angular, consider running the [dev-app ](../dev-app/README.md ) in this repository.
2025-12-30 08:18:13 +00:00
**Prerequisites:**
- [Docker Desktop ](https://www.docker.com/products/docker-desktop )
- [VS Code ](https://code.visualstudio.com/ )
- [Dev Containers extension ](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers )
**Usage:**
1. Open the Angular repository in VS Code.
2. Run the **Dev Containers: Reopen in Container** command from the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P` ).
2015-03-18 01:48:02 +00:00
## Getting the Sources
2015-04-17 23:02:42 +00:00
Fork and clone the Angular repository:
2015-03-18 01:48:02 +00:00
2015-04-17 23:02:42 +00:00
1. Login to your GitHub account or create one by following the instructions given
2015-03-18 01:48:02 +00:00
[here ](https://github.com/signup/free ).
2020-11-16 21:37:09 +00:00
2. [Fork ](https://help.github.com/forking ) the [main Angular
2015-03-18 01:48:02 +00:00
repository](https://github.com/angular/angular).
3. Clone your fork of the Angular repository and define an `upstream` remote pointing back to
2015-04-17 23:02:42 +00:00
the Angular repository that you forked in the first place.
2015-03-18 01:48:02 +00:00
```shell
2015-04-17 23:02:42 +00:00
# Clone your GitHub repository:
2015-03-18 01:48:02 +00:00
git clone git@github.com:< github username > /angular.git
# Go to the Angular directory:
cd angular
# Add the main Angular repository as an upstream remote to your repository:
git remote add upstream https://github.com/angular/angular.git
```
2019-10-23 12:49:11 +00:00
2016-07-21 18:48:23 +00:00
## Installing NPM Modules
2015-03-18 01:48:02 +00:00
2016-08-17 02:38:49 +00:00
Next, install the JavaScript modules needed to build and test Angular:
2015-03-18 01:48:02 +00:00
```shell
# Install Angular project dependencies (package.json)
2025-07-31 15:17:27 +00:00
pnpm install
2015-03-18 01:48:02 +00:00
```
2016-07-08 19:00:27 +00:00
## Building
2015-03-18 01:48:02 +00:00
2016-07-08 19:00:27 +00:00
To build Angular run:
2015-03-18 01:48:02 +00:00
```shell
2025-07-31 15:17:27 +00:00
pnpm build
2015-03-18 01:48:02 +00:00
```
2025-11-06 18:03:05 +00:00
- Results are put in the `dist/packages-dist` folder.
2015-03-18 01:48:02 +00:00
## Running Tests Locally
2022-05-21 17:12:05 +00:00
Bazel is used as the primary tool for building and testing Angular.
2015-11-06 23:16:53 +00:00
2024-05-28 23:15:16 +00:00
To see how to run and debug Angular tests locally please refer to the
2024-07-04 12:28:55 +00:00
Bazel [Testing Angular ](./building-with-bazel.md#testing-angular ) section.
2016-07-14 15:51:05 +00:00
2024-05-28 23:15:16 +00:00
Note that you should execute all test suites before submitting a PR to
2025-07-31 15:17:27 +00:00
GitHub (`pnpm test //packages/...`).
2021-10-19 14:34:00 +00:00
2024-05-28 23:15:16 +00:00
However, affected tests will be executed on our CI infrastructure. So if you forgot to run some
affected tests which would fail, GitHub will indicate the error state and present you the failures.
2019-03-01 01:09:46 +00:00
2022-05-21 17:12:05 +00:00
PRs can only be merged if the code is formatted properly and all tests are passing.
2016-07-14 15:51:05 +00:00
2024-05-28 23:15:16 +00:00
< a name = "formatting-your-source-code" > < / a >
2019-10-23 12:49:11 +00:00
< a name = "clang-format" > < / a >
< a name = "prettier" > < / a >
2020-06-02 12:19:24 +00:00
2025-08-15 13:18:02 +00:00
### Testing changes against a local library/project
Often for developers the best way to ensure the changes they have made work as expected is to run
use changes in another library or project. To do this developers can build Angular locally, and
using `pnpm link` build a local project with the created artifacts.
This can be done by running:
```sh
pnpm ng-dev misc build-and-link < path-to-local-project-root >
```
2022-09-13 20:04:47 +00:00
### Building and serving a project
#### Cache
2024-05-28 23:15:16 +00:00
When making changes to Angular packages and testing in a local library/project you need to
run `ng cache disable` to disable the Angular CLI disk cache. If you are making changes that are not
reflected in your locally served library/project, verify if you
2025-06-21 22:55:52 +00:00
have [CLI Cache ](https://angular.dev/reference/configs/workspace-config#cache-options ) disabled.
2022-09-13 20:04:47 +00:00
#### Invoking the Angular CLI
2024-05-28 23:15:16 +00:00
The Angular CLI needs to be invoked using
Node.js [`--preserve-symlinks` ](https://nodejs.org/api/cli.html#--preserve-symlinks ) flag. Otherwise
the symbolic links will be resolved using their real path which causes node module resolution to
fail.
2022-09-13 20:04:47 +00:00
2023-05-30 10:24:57 +00:00
```sh
2023-05-30 12:10:10 +00:00
node --preserve-symlinks --preserve-symlinks-main node_modules/@angular/cli/lib/init.js serve
2023-05-30 10:24:57 +00:00
```
2022-09-13 20:04:47 +00:00
2019-10-23 12:49:11 +00:00
## Formatting your source code
2016-07-14 15:51:05 +00:00
2024-11-19 21:42:14 +00:00
Angular uses [prettier ](https://prettier.io ) to format the source code.
2019-02-28 23:40:09 +00:00
If the source code is not properly formatted, the CI will fail and the PR cannot be merged.
2016-07-14 15:51:05 +00:00
You can automatically format your code by running:
2024-05-28 23:15:16 +00:00
2025-07-31 15:17:27 +00:00
- `pnpm ng-dev format changed [shaOrRef]` : format only files changed since the provided
2024-05-28 23:15:16 +00:00
sha/ref. `shaOrRef` defaults to `main` .
2025-07-31 15:17:27 +00:00
- `pnpm ng-dev format all` : format _all_ source code
- `pnpm ng-dev format files <files..>` : format only provided files
2016-07-14 15:51:05 +00:00
2019-10-23 12:49:11 +00:00
## Linting/verifying your Source Code
2016-12-31 02:54:53 +00:00
You can check that your code is properly formatted and adheres to coding style by running:
2025-11-06 18:03:05 +00:00
```shell
2025-09-13 18:13:37 +00:00
pnpm lint
2016-12-31 02:54:53 +00:00
```
2019-10-23 12:49:11 +00:00
## Publishing Snapshot Builds
2017-01-19 22:25:44 +00:00
2024-05-28 23:15:16 +00:00
When a build of any branch on the upstream fork angular/angular is green on CI, it
2022-08-29 20:17:17 +00:00
automatically publishes build artifacts to repositories in the Angular org. For example,
the `@angular/core` package is published to https://github.com/angular/core-builds.
2016-07-14 15:51:05 +00:00
2016-12-15 19:19:21 +00:00
You may find that your un-merged change needs some validation from external participants.
2019-10-22 13:57:13 +00:00
Rather than requiring them to pull your Pull Request and build Angular locally, they can depend on
snapshots of the Angular packages created based on the code in the Pull Request.
2020-06-18 05:36:30 +00:00
### Publishing to GitHub Repos
2024-05-28 23:15:16 +00:00
You can also manually publish `*-builds` snapshots just like our CI build does for upstream
2019-10-22 13:57:13 +00:00
builds. Before being able to publish the packages, you need to build them locally by running the
2025-07-31 15:17:27 +00:00
`pnpm build` command.
2016-12-15 19:19:21 +00:00
2019-03-01 01:09:46 +00:00
First time, you need to create the GitHub repositories:
2016-12-15 19:19:21 +00:00
2025-11-06 18:03:05 +00:00
```shell
2016-12-15 19:19:21 +00:00
$ export TOKEN=[get one from https://github.com/settings/tokens]
2025-10-10 18:38:05 +00:00
$ CREATE_REPOS=1 ./scripts/ci/publish-snapshot-build-artifacts.sh [GitHub username]
2016-12-15 19:19:21 +00:00
```
2019-10-23 12:49:11 +00:00
For subsequent snapshots, just run:
2016-12-15 19:19:21 +00:00
2025-11-06 18:03:05 +00:00
```shell
2025-10-10 18:38:05 +00:00
$ ./scripts/ci/publish-snapshot-build-artifacts.sh [GitHub username]
2016-12-15 19:19:21 +00:00
```
2016-12-20 22:52:50 +00:00
The script will publish the build snapshot to a branch with the same name as your current branch,
and create it if it doesn't exist.
2018-11-21 16:03:37 +00:00
2019-10-23 12:49:11 +00:00
## Bazel Support
2019-10-11 19:03:59 +00:00
### IDEs
2019-10-23 12:49:11 +00:00
2019-10-11 19:03:59 +00:00
#### VS Code
2018-11-21 16:03:37 +00:00
2024-05-28 23:15:16 +00:00
1. Install [Bazel ](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel )
extension for VS Code.
2019-03-01 01:09:46 +00:00
2019-10-11 19:03:59 +00:00
#### WebStorm / IntelliJ
2024-05-28 23:15:16 +00:00
2019-03-01 01:09:46 +00:00
1. Install the [Bazel ](https://plugins.jetbrains.com/plugin/8609-bazel ) plugin
2024-05-28 23:15:16 +00:00
2. You can find the settings under `Preferences->Other Settings->Bazel Settings`
2019-03-01 01:09:46 +00:00
It will automatically recognize `*.bazel` and `*.bzl` files.
2019-10-11 19:03:59 +00:00
### Remote Build Execution and Remote Caching
2024-05-28 23:15:16 +00:00
Bazel builds in the Angular repository use a shared cache. When a build occurs, a hash of the inputs
is computed
and checked against available outputs in the shared cache. If an output is found, it is used as the
output for the
2019-10-17 19:04:06 +00:00
build action rather than performing the build locally.
2022-06-27 14:51:22 +00:00
> Remote Build Execution requires authentication as a google.com account.
2019-10-11 19:03:59 +00:00
2019-10-23 12:49:11 +00:00
#### --config=remote flag
2024-05-28 23:15:16 +00:00
2022-06-27 14:51:22 +00:00
The `--config=remote` flag can be added to enable remote execution of builds.