{ "id": "cli", "title": "CLI Overview and Command Reference", "contents": "\n\n\n
\n mode_edit\n
\n\n\n
\n

CLI Overview and Command Referencelink

\n

The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command shell.

\n

Installing Angular CLIlink

\n

Major versions of Angular CLI follow the supported major version of Angular, but minor versions can be released separately.

\n

Install the CLI using the npm package manager:\n\nnpm install -g @angular/cli\n

\n

For details about changes between versions, and information about updating from previous releases,\nsee the Releases tab on GitHub: https://github.com/angular/angular-cli/releases

\n

Basic workflowlink

\n

Invoke the tool on the command line through the ng executable.\nOnline help is available on the command line.\nEnter the following to list commands or options for a given command (such as generate) with a short description.

\n\nng help\nng generate --help\n\n

To create, build, and serve a new, basic Angular project on a development server, go to the parent directory of your new workspace use the following commands:

\n\nng new my-first-project\ncd my-first-project\nng serve\n\n

In your browser, open http://localhost:4200/ to see the new app run.\nWhen you use the ng serve command to build an app and serve it locally, the server automatically rebuilds the app and reloads the page when you change any of the source files.

\n
\n

When you run ng new my-first-project a new folder, named my-first-project, will be created in the current working directory. Since you want to be able to create files inside that folder, make sure you have sufficient rights in the current working directory before running the command.

\n

If the current working directory is not the right place for your project, you can change to a more appropriate directory by running cd <path-to-other-directory> first.

\n
\n

Workspaces and project fileslink

\n

The ng new command creates an Angular workspace folder and generates a new app skeleton.\nA workspace can contain multiple apps and libraries.\nThe initial app created by the ng new command is at the top level of the workspace.\nWhen you generate an additional app or library in a workspace, it goes into a projects/ subfolder.

\n

A newly generated app contains the source files for a root module, with a root component and template.\nEach app has a src folder that contains the logic, data, and assets.

\n

You can edit the generated files directly, or add to and modify them using CLI commands.\nUse the ng generate command to add new files for additional components and services, and code for new pipes, directives, and so on.\nCommands such as add and generate, which create or operate on apps and libraries, must be executed from within a workspace or project folder.

\n\n

Workspace and project configurationlink

\n

A single workspace configuration file, angular.json, is created at the top level of the workspace.\nThis is where you can set per-project defaults for CLI command options, and specify configurations to use when the CLI builds a project for different targets.

\n

The ng config command lets you set and retrieve configuration values from the command line, or you can edit the angular.json file directly.\nNote that option names in the configuration file must use camelCase, while option names supplied to commands can use either camelCase or dash-case.

\n\n

CLI command-language syntaxlink

\n

Command syntax is shown as follows:

\n

ng commandNameOrAlias requiredArg [optionalArg] [options]

\n\n

Boolean optionslink

\n

Boolean options have two forms: --this-option sets the flag to true, --no-this-option sets it to false.\nIf neither option is supplied, the flag remains in its default state, as listed in the reference documentation.

\n

Relative pathslink

\n

Options that specify files can be given as absolute paths, or as paths relative to the current working directory, which is generally either the workspace or project root.

\n

Schematicslink

\n

The ng generate and ng add commands take as an argument the artifact or library to be generated or added to the current project.\nIn addition to any general options, each artifact or library defines its own options in a schematic.\nSchematic options are supplied to the command in the same format as immediate command options.

\n\n
\n\n

Command Overviewlink

\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n\n
CommandAliasDescription
add

Adds support for an external library to your project.

\n
analytics

Configures the gathering of Angular CLI usage metrics. See https://angular.io/cli/usage-analytics-gathering.

\n
buildb

Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.

\n
config

Retrieves or sets Angular configuration values in the angular.json file for the workspace.

\n
deploy

Invokes the deploy builder for a specified project or for the default project in the workspace.

\n
docd

Opens the official Angular documentation (angular.io) in a browser, and searches for a given keyword.

\n
e2ee

Builds and serves an Angular app, then runs end-to-end tests using Protractor.

\n
extract-i18ni18n-extract xi18n

Extracts i18n messages from source code.

\n
generateg

Generates and/or modifies files based on a schematic.

\n
help

Lists available commands and their short descriptions.

\n
lintl

Runs linting tools on Angular app code in a given project folder.

\n
newn

Creates a new workspace and an initial Angular application.

\n
run

Runs an Architect target with an optional custom builder configuration defined in your project.

\n
serves

Builds and serves your app, rebuilding on file changes.

\n
testt

Runs unit tests in a project.

\n
update

Updates your application and its dependencies. See https://update.angular.io/

\n
versionv

Outputs Angular CLI version.

\n
\n\n\n" }