Tuesday, April 15, 2025

Angular CLI Commands Cheat Sheet (2025 Edition)

 

⚡️ Angular CLI Commands Cheat Sheet

๐Ÿ“ฆ Project Setup

CommandDescription
ng new <project-name>Create a new Angular project
ng add <package>Add a package and run schematics (e.g., @angular/material)
ng configView or set config values in angular.json
ng analyticsEnable or disable analytics

๐Ÿš€ Serve & Build

CommandDescription
ng serveServe the app locally with hot reload
ng serve --port=4201Serve app on a custom port
ng buildBuild app for production
ng build --configuration=developmentBuild in dev mode
ng build --watchRebuild on file changes

๐Ÿ›  Generate Code (Schematics)

CommandDescription
ng generate component <name> or ng g c <name>Generate a component
ng g s <name>Generate a service
ng g m <name>Generate a module
ng g d <name>Generate a directive
ng g p <name>Generate a pipe
ng g i <name>Generate an interface
ng g guard <name>Generate a route guard
ng g class <name>Generate a TypeScript class

๐Ÿ“‚ Routing & Modules

CommandDescription
ng g module <name> --routingGenerate a module with routing
ng g component <name> --module=appRegister component in specific module
ng g module <name> --standaloneGenerate a standalone module/component (Angular 17+)

๐Ÿงช Testing

CommandDescription
ng testRun unit tests with Karma
ng test --watch=falseRun tests once and exit
ng e2eRun end-to-end tests (with Protractor or Cypress setup)

๐Ÿ“ˆ Linting, Format, & Analysis

CommandDescription
ng lintRun lint checks (ESLint if configured)
ng lint --fixAuto-fix lint errors
ng doc <keyword>Open Angular docs (e.g., ng doc directive)

๐Ÿ“ค Deployment & Misc

CommandDescription
ng deployDeploy via configured builder (e.g., Firebase, Netlify)
ng updateUpdate Angular CLI and core packages
ng versionShow Angular versions
ng helpList all CLI commands
ng cache cleanClear Angular build cache

๐Ÿ’ก Tips

  • Use --dry-run on any ng g command to preview changes.

  • Use --skip-tests if you don’t want spec files generated.

  • Combine flags like:
    ng g c user/profile --standalone --flat

No comments:

Post a Comment