ANGULAR CLI Commands
ANGULAR
Angular CLI commands are useful for creating, building, scaffolding, and maintaining Angular applications.
Key features of Angular CLI commands.
➔ Automate tasks: Angular CLI automates repetitive tasks such as project setup, component creation, building, and testing projects.
➔ Code Generation: Angular CLI commands add new features or modify an existing one, such as the ng generate service command that creates a new service and makes it available to others.
➔ Run Server: The ng serve command runs a local development server to test the project with the live-reload feature, which provides instant updates when any changes are made to the code.
➔ Build optimization: The ng build CLI command generates a production ready application bundle that is optimized to reduce project size through the code minification process.
➔ Testing Automation: CLI commands like ng test and ng e2e can work with testing frameworks for unit and end to end testing.
➔ Documentation help: The CLI command ng doc
CLI Commands Example
- All Angular command syntax start with ie. ng [command] [options]
- Most commands, and some options, have aliases.
- Option names are prefixed with double dash (--) characters where as option aliases are prefixed with a single dash (-) character. Commands are not prefixed by anything.
- Most commands are used with the schematic command like
ng [commnad schematic]. Example:ng generate component user. Here component is the schematic name and can be changed.
To get help
ng help
ng generate --help
ng generate component user --inline-style --inline-template
ng g c user -s -t
To create project
ng new my-first-project
cd my-first-project
ng serve
To create component
ng generate component componentName
ng g c componentName
To create class
ng generate class className
ng g cl className
To create service
ng generate service serviceName
ng g s serviceName
Basic CLI Commands
| Command | Alias | Description |
|---|---|---|
| add | This command adds support for an external library to the project. | |
| analytics | This command configures the collection of Angular CLI usage metrics. | |
| build | b | This command compiles an Angular application or library into an output directory named dist/ at the given output path. |
| cache | It configures persistent disk cache and retrieves cache statistics. | |
| completion | This sets up Angular CLI autocompletion for the terminal. | |
| config | It retrieves or sets the Angular configuration values in the angular.json file.. | |
| deploy | This invokes the builder to a specific project or to the default project in the workspace. | |
| doc | This opens the Angular documentation in a browser. | |
| e2e | It builds, serves, and then runs end-to-end tests. | |
| extract-i18n | It extracts the i18n message from the source code. | |
| generate | g | This command creates a new file or modifies an existing file based on an Angular entity. |
| lint | These options allow linting tools to be run on Angular application code. | |
| new | n | This command creates a new Angular project. |
| run | It runs a target Angular project. | |
| serve | s | This command builds and serves the application. |
| test | t | This command runs unit tests on a project. |
| update | Updates the project and its dependencies. | |
| version | v | This shows the Angular CLI version. |