Angular CLI Commands Every Developer Should Know
Angular CLI Commands Every Developer Should Know
The Angular CLI is your best friend for productivity. Here are essential commands.
Project setup:
- ng new my-app: Create new project
- ng new my-app --routing --style=scss: With routing and SCSS
Generation commands:
- ng g c component-name: Generate component
- ng g s service-name: Generate service
- ng g m module-name: Generate module
- ng g p pipe-name: Generate pipe
- ng g d directive-name: Generate directive
- ng g guard guard-name: Generate route guard
- ng g interceptor name: Generate interceptor
Build and serve:
- ng serve: Development server with hot reload
- ng build --configuration production: Production build
- ng build --stats-json: Generate bundle stats
Testing:
- ng test: Run unit tests
- ng e2e: Run end-to-end tests
Useful flags:
- --dry-run: Preview changes without creating files
- --skip-tests: Skip test file generation
- --flat: Don't create subdirectory
What CLI commands do you use most often?
The Angular CLI is an indispensable tool that dramatically speeds up development workflow. Commands like ng generate save so much time by scaffolding components, services, and modules with proper file structure. The ng build and ng serve commands with their various flags make development and deployment seamless. I especially find ng update useful for keeping dependencies current across Angular versions.