×

Angular CLI Commands

All CLI commands of Angular

Angular CLI is a command-line interface which is used to initialize, develop, and maintain Angular applications. We can use these Command on command prompt or consequentially by an associated UI.  i.e., Angular Console.

Command Alias Description
add   It used to add support for an external library to the Project.
build b It compiles an Angular app in an output directory "dist" at the given output path. Must be executed within a workspace directory.
config   It retrieves Angular configuration values in the angular.json file for the workspace directory.
doc d It opens the official Angular site (angular.io) in the browser and also searches for any given keywords. 
e2e e It builds and serves an Angular app, and then runs the end-to-end test using a protractor.
generate g It generates or modifies files based on a schedule.
help   It provides a list of possible commands and short descriptions.
lint l It runs linting tools on the Angular app in a given project folder.
new n It creates a workspace and a first Angular app.
run   It runs an architecture target with an optional custom builder configuration in our descriptions.
serve s It builds and helps our app, rebuilding on files changes.
test t It runs unit tests in a project.
update   It updates our application and its dependencies.
version v It updates the Angular CLI version.
Xi18n   It extracts i18n messages from source code.

1. ng add Command

The ng add Command add support of an external library in our Project. It combines the npm package for a published library to your workspace and makes your default app project to use that library.

The default app project is the primary value of the default project in angular.json.

Syntax:

ng add 
 [options] 

Parameter Explanation:

Options

--default=true|false: Whentrue, it disables interactive input prompts for option with a default.

--help=true|false|json|JSON: It generates a help message in the console. Default:false.

--interactive= true|false:  it disables interactive input prompts,when false.

2.ng build Command

The ng build command is used to compile an angular app into an output directory file "dist" at the following output path. It may be executed from within a workspace directory.

Syntax:

ng build < Project>
 [options]

Parameter Explanation:

< Project>:It describes the name of the Project, which builds. It can be an app or library.

Options

--aot=true|false: It builds ahead of Time compilation.

Default: false

--baseHref=baseHref: It specifies the base URL for the application being built.

--buildEventLog=buildEventLog:  It is an output file path for build event protocol event.

--buildOptimizer=true|false: It enables "@angular-devkit/build-optimizer"  for optimization when using the "aot" option.

Default: false

--commonChunk=true|false: It has used a separate bundle contains code used across multiple packages. Default: true

--configuration=configuration: It is a named build target, which specified in the "configurations" section of angular.json and each designated target is accompanied by a configuration of options default for the goal.

Aliases: -c

--deleteOutputPath= true|false: It was used to delete the output path before it is building. Default: true

--deployUrl=deployUrl:  The URL where files will be deployed.

--es5BrowserSupport= true|false: Enables dependency loaded ES2015 polyfills.

Default: false

--extractCss=true|false: It has used to extract CSS from the global styles into CSS files instead of js ones.

Default: false

--forkTypeChecker=true|false: It has been used to run the Typescript typechecker in a forked process. Default: true

--help= true|false|json|JSON:It is mainly used to show a help message for this Command in the console. Default: false

--i18nFile= i18nFile: i18n is used to locale.

--i18nMissingTranslation=i18nMissingTranslation: How to handle missing translation for i18n.

--index=index: The name of index HTML file.

--lazyModules: List of additional ngModules files will be lazy loaded. Lazy router modules have been discovered unwittingly.

--main=main: The full path in the main entry point to the app is completely relative to the current workspace.

--namedChunks=true|false: Use filename for lazy loaded chunk Default: true

--ngswConfigPath=ngswConfigPath: Path to ngsw-config.json.

--outputHashing=none|all|media|bundles: Define the outputs of filename cache-busting and hashing mode.

Default: none

--outputPath=outputPath:The full path of the new output directory directly relative to the current workspaces.

By default, write output to a folder named "dist \" in the current Project.

--poll:Enables and define the file watching poll time in milliseconds.

--polyfills=polyfills: The full path for the polyfill files is relative to current workspaces.

--preserveSymlinks=true|false: It do not use the real way when resolving modules.

Default: false

--prod=true|false: Sets the build configuration in the production target. All builds make use of packaging and little tree-shaking. A production build runs limited dead code elimination, when true.

--profile=true|false: Output profile events is used in Chrome profiler.

Default: false

--progress=true|false: it progress to the console during building.

--resourcesOutputPath= resourcesOutputPath:The path where style resources would place is combined to outputPath.

--serviceWorker=true|false: It generates a service worker config in the production build. Default: false.

--showCircularDependencies=true|false: Show circular dependency warning on the build. Default: true

--sourceMap=true|false: It is showed Output source maps.

--statsJson=true|false: It generates a "stats.json" file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or http://webpack.github.io/analyse.

--subresourceIntegrity=true|false: It qualifies the use of subresource integrity and validation.

--tsConfig=tsConfig: The full path of the Typescript configuration file is comparative to the current workspaces.

--vendorChunk=true|false: It mostly uses a separate bundle which contains the vendor libraries.

Default: true

--verbose=true|false: It adds more details of output logging.

Default: false

--watch= true|false: It builds when a file changes.

Default: false

3. ng config Command

The ng command is used to retrieve and set Angular configuration values in the angular.json file of the workspaces.

Syntax:

ng config \
 [options] 

Parameter Explanation:

<jsonPath>: The configuration key is used to set or query, in JSON path format. For example: "a[3].foo.bar[2]". If there is no new value is provided, results the current value of that key.

<value>:  A new value for the given configuration key, if provided.

Options

--global=true|false: It accesses the global configuration in the caller's home directory.

Default: false

Aliases: -g

--help= true|false|json|JSON: It has used to show a help message for this Command in the console.

Default: false

4. ng doc Command

The ng doc command is used to open Angular documentation site "angular.io" in a browser and searches for a given keyword.

Syntax:

ng doc 
 [options]

Parameter Explanation:

<keyword>: It is used to identify the keyword to search for, as provided in the search bar in angular.io.

Options

--help= true|false|json|JSON:It generates a helping message for this Command in the console.

Default: false

5.ng e2e Command

It has used to build and serve an Angular application, that runs end-to-end tests using Protractor.

Syntax:

ng e2e 
 [options] 

It must be executed form within a workspace directory. When we don’t specify the project name, it executes for all projects.

Parameter Explanation:

< Project>: It identifies the name of the Project we want to build. It can be any app or library.

Options:

--baseUrl=baseUrl: It specifies the base URL of the Protractor to connect.

--configuration=configuration: It is used to determine build target, as is specified in the <configurations> section of angular.json. An arrangement of option defaults accompanies each named target for the goal.

Aliases: -c

--devServerTarget=devServerTarget: It specifies dev server  which target to run tests.

--elementExplorer=true|false: It start Protractor's Element  used to explorer for debugging process.

Default: false

--help= true|false|json|JSON: It has seen a help message for this Command in the console line.

Default: false

--host=host: it is used to listen on the host.

Default: localhost

--port: It modifies the port to serve the application.

--prod=true|false:  it sets the build configuration to the production target when it is true. All build uses bundling and limited tree-shaking techniques. A production build runs limited dead code elimination.

--protractorConfig= protractorConfig: It implies the name of the Protractor configuration file.

--specs: It overrides spec in protractor config.

--suite=suite: It overrides suite on the protractor configuration.

--webdriverUpdate=true|false: It is worn to update the web driver.

Default: true

6. ng generate Command

Syntax:

ng generate

Parameter Explanation:

It specifies the schematic or collection: which we want to generate, and it can take one of the following sub-commands.

  • appShell
  • application
  • class
  • component
  • directive
  • enum
  • guard
  • interface
  • library
  • module
  • pipe
  • service
  • service Worker
  • universal

Schematic Command

appShell:

It was used to generate an app shell for creating a server-side version of an app.

Syntax:

Ng generate appShell
[options]or
Ng g appshell
[options] 

application

It is used to create a basic app definition in the "projects" subfolder of the workspace.

Syntax:

ng generate application
or
ng g application
 [options]  

class

It creates a new generic class in the given or default project.

Syntax:

ng generate class

[options]or
ng g class 
[options]  

component

It can create a new generic component definition in the given or default project.

Syntax:

ng generate
component or
ng g component
 [options] 

directive

It is mainly used to create a new generic directive definition in the given or default project.

Syntax:

ng generate directive 
[options]or
ng g directive
 [options] 

enum

It create a new, generic enum definition for the given or default project.

Syntax:

ng generate enum 
[options]or
ng g enum  
[options]

guard

It is used to generate a new and generic route definition in the given or default project.

Syntax:

ng generate enum
 [options]or
ng g enum 
[options] 

interface

It create a new generic interface definition in the given or default project.

Syntax:

ng generate interface 
 [options] or
ng g interface

[Options] 

Library

It can used to create a new generic library project in the current workspace.

Syntax:

 ng generate library
 [options] or
 ng g library 
 [options] 

Module

It creates a new generic NgModule definition in the given or default project.

Syntax:

 ng generate module
  [options] or
 ng g module 
 [options] 

Pipe

It creates a new generic pipe definition in the given or default project.

Syntax:

 ng generate pipe
  [options] 

Service

It is used to create a new and generic service definition in the given or default project.

Syntax:

 ng generate service
 [options] 

serviceWorker

It is used to pass this to "run" Command to create a service worker.

Syntax:

ng generate
serviceWorker 

universal

This Command is used to pass this simplified to the "run" command to set up server-side rendering for an app.

Syntax:

ng generate
 universal  [options] 

Options

--default=true|false:When true, it disables interactive input prompts for options with a default.

-dryRun=true|false: When true, it runs through and reports activity without writing out results.

Default: false

Aliases: -d

--force=true|false: It forces overwriting of existing files, when true

Default: false

Aliases: -f

--help=true|false|json|JSON:  Used to show a help message in the console.

Default: false

--interactive=true|false: When it is false, it disables interactive input prompts.


Related Topics

Advantages | Disadvantages of Angular 8

Advantages of Angular 8 There are some Advantages of angular 8 which are given below: It offers clean code developmentHigher PerformanceAn angular framework can take care of routing, which...

1 minute read.

Deployment of an Angular 8 app

Deploying an Angular 8 app To implement our application, we have to compile it and then host the JavaScript, CSS, and HTML on a web server. Build an Angular application which is very portable...

4 minutes read.

Angular CLI Commands

All CLI commands of Angular Angular CLI is a command-line interface which is used to initialize, develop, and maintain Angular applications. We can use these Command on command prompt or consequentially by an associated...

8 minutes read.

$timeout service in AngularJS

The discipline of web development is expanding quickly. A technology that is released today will inevitably become obsolete in a few months. The webpages were static in the past and...

4 minutes read.

Angular 8 App Loading

How an Angular 8 app loaded and started When we create an Angular app and run it by using ng serve command, it looks like the below screenshot. It is a simple...

3 minutes read.

Angular 8 universal

Angular 8 universal Angular Universal is a technology that allows server-side rendering for Angular apps. An angular app is a single-page app, and it runs in a client-side browser. Rendering pages in the DOM is...

6 minutes read.

Angular 8 *ngFor Directive

Angular 8ngFor Directive The *ngFor directive is used to repeat to repeat a portion of HTML template once per each item from an iterable list (collection). The ngFor is an Angular...

2 minutes read.

Difference between Angular and React

Difference between Angular and React Parameters AngularReactType Angular is a complete framework. React is a JavaScript library, and much older compared...

2 minutes read.

Angular 8 NgStyle Directive

Angular 8 NgStyle Directive The ngStyle attribute is used to change and style the multiple properties of Angular. We can change the value, color, and size, etc. of the component. It is a built-in...

1 minute read.

String Interpolation in Angular 8

String Interpolation in Angular 8 String interpolation is a one-way data-binding technique which is used to output the data from a typescript code to HTML template. It uses the template expression. It uses the...

2 minutes read.

Angular 8 ngClass Directive

Angular 8 ngClass Directive ngClass Directive is a type of attribute directive. Angular provided built-in directive, and it helps in adding or removing CSS classes on an HTML element. The ngClass directive allows...

2 minutes read.

Difference between Node.js and ASP.net

Introduction to Node.js V8 (the JavaScript engine operating inside Google Chrome) is packaged with certain libraries and is mostly used for input & output, which includes creating data and managing connection...

4 minutes read.

History and Versions of Angular 8

Introduction to Angular JS Misko created Angular JS and the first version of Angular also name as "Angular 1". He built a framework to handle the downfalls of HTML. The first...

3 minutes read.

Angular 8 Pipes

Angular 8 Pipes Pipes are a useful feature in Angular. These are the simple way to transform values in an Angular template. It takes the integers, strings, array, and dates as input separated with...

3 minutes read.

Express.js app.listen() Function

Express or Express.js is a flexible online application framework for Node.js that offers a strong set of functionality for both web and mobile applications. While preserving the familiar and adored...

3 minutes read.

Angular 8 Libraries

Angular libraries are built a solution of general problems like presenting a unified user interface, presenting data, and allowing the data entry. Developers can create standard solutions for particular domains...

3 minutes read.

ngSwitch Directive in Angular 8

Angular 8 ng-Switch Directive The ng-Switch Directive hides and shows the HTML elements depending on an expression. Child elements with the ng-switch-when directive will be displayed if it gets a match; otherwise, the component and...

2 minutes read.

Angular 8 Module

Angular 8 Module It is a collection of services, directives, controllers, filters, and configuration information. angular.module is used to configure the $injector. The module is a container of the different parts of an application....

6 minutes read.

Angular 8 with Bootstrap

How to install Bootstrap for Angular? Run the following Command in Command prompt. npm install–save bootstrap@3= > The @3 is essential! After that, when we use a project created with Angular CLI 6+, we will...

1 minute read.

Installation of Angular 8

Installation Guides to Angular 8 step by Step Angular combines declarative templates, dependency injection and, end to end tooling to solve development challenges. Angular empowers developers to build an application that lives on the...

4 minutes read.