Here is a list of the most commonly used Angular CLI commands:
Global Angular CLI Commands
Install Angular CLI
Installs the Angular CLI globally:bashnpm install -g @angular/cli
Check Angular CLI Version
Displays the version of the installed Angular CLI:bashng version
Help Command
Displays help for available commands:bashng help
Project Management Commands
Create a New Angular Project
Creates a new Angular project:bashng new project-name
Run Development Server
Runs the app locally with live reload:bashng serve
Build Project for Production
Builds the project for production:bashng build --prod
Run Unit Tests
Runs unit tests with Karma:bashng test
Run End-to-End Tests
Runs end-to-end tests using Protractor:bashng e2e
Updating and Maintenance Commands
Update Angular Dependencies
Updates Angular to a newer version:bashng update @angular/core @angular/cli
Add New Dependencies or Features
Adds a new package or Angular features (e.g., PWA, Material):bashng add package-name
Linting Project
Lints the project and checks for coding standards:bashng lint
Run Code Formatting (Prettier)
If you have Prettier installed, format the project files:bashnpx prettier --write .
Generating Code
Generate a Component
Creates a new Angular component:bash<ng generate component component-name # or shorthand: ng g c component-name
Generate a Service
Creates a new Angular service:bashng generate service service-name # or shorthand: ng g s service-name
Generate a Module
Creates a new Angular module:bashng generate module module-name # or shorthand: ng g m module-name
Generate a Directive
Creates a new Angular directive:bashng generate directive directive-name # or shorthand: ng g d directive-name
Generate a Pipe
Creates a new Angular pipe:bashng generate pipe pipe-name # or shorthand: ng g p pipe-name
Generate a Guard
Creates a new Angular guard:bashng generate guard guard-name # or shorthand: ng g g guard-name
Generate a Class/Interface/Enum
Generates classes, interfaces, and enums:bashng generate class class-name ng generate interface interface-name ng generate enum enum-name
Miscellaneous Commands
Run a Custom Script
Runs a custom npm script from thepackage.json
:bashnpm run script-name
Run Server with a Specific Port
Runs the development server on a custom port:bashng serve --port 4201
Open Project in Default Browser
Opens the app in the default browser while serving:bashng serve --open
Analyze Build Size
Generates a production build and analyzes the bundle size:bashng build --prod --stats-json npx webpack-bundle-analyzer dist/project-name/stats.json
Deployment Commands
- Deploy to GitHub Pages
Deploys the project to GitHub Pages (after adding angular-cli-ghpages):bashng add angular-cli-ghpages ng deploy
These commands cover most tasks you’ll perform while developing Angular applications.
0 Comments