Course Progress 12%

Angular CLI

Angular CLI (Command Line Interface) Angular का official tool है, जिसकी मदद से Angular applications को create, develop, test और build किया जाता है। Angular CLI development को fast, structured और error-free बनाता है, इसलिए real-world Angular projects में इसका use almost mandatory होता है।

इस chapter में आप सीखेंगे:

  • Angular CLI क्या है
  • Angular CLI क्यों जरूरी है
  • Common Angular CLI commands
  • Project generate और manage कैसे करें
  • CLI best practices

Angular CLI क्या है

Angular CLI एक command-line tool है जो Angular framework के साथ tightly integrated होता है।
यह automatically best practices follow करता है और complex configuration को handle करता है।

Angular CLI internally:

  • Webpack / build system
  • TypeScript compilation
  • Development server
  • Testing setup

को manage करता है।

Angular CLI क्यों जरूरी है

Angular CLI के बिना:

  • Manual configuration करनी पड़ेगी
  • Errors और inconsistency बढ़ेंगी

Angular CLI के साथ:

  • Project structure standard रहता है
  • Code generation fast होता है
  • Build और test easy हो जाते हैं

Angular CLI Install और Version Check

CLI install करने के लिए:

npm install -g @angular/cli

Version check करने के लिए:

ng version

Explanation

  • Angular CLI और Angular packages की versions दिखती हैं
  • Environment compatibility check होती है

Angular CLI से Project Create करना

ng new my-app

Explanation

  • नया Angular project create होता है
  • Routing और stylesheet options CLI पूछता है
  • Best default configuration set होती है

Development Server Start करना

ng serve

Explanation

  • Local server start होता है
  • Default port 4200 होता है
  • Live reload automatically work करता है

Custom port के लिए:

ng serve --port 4300

Angular CLI Project Structure Generate करना

Angular CLI से components, services, directives generate किए जाते हैं।

Generate Component

ng generate component users

या short form:

ng g c users

Explanation

  • Component folder create होता है
  • HTML, CSS, TS और spec files generate होती हैं

Generate Service

ng g service data

Explanation

  • Service class generate होती है
  • Dependency Injection ready होती है

Generate Other Angular Parts

ng g directive highlight
ng g pipe filterText
ng g guard auth
ng g interceptor auth

Explanation

  • CLI automatically correct boilerplate create करता है
  • Manual errors avoid होते हैं

Angular CLI Build Command

Production build के लिए:

ng build

Production optimized build:

ng build --configuration=production

Explanation

  • Optimized bundles generate होते हैं
  • Minification और tree-shaking apply होती है

Angular CLI Testing Commands

Unit tests run करने के लिए:

ng test

End-to-End tests के लिए:

ng e2e

Explanation

  • Karma और Jasmine automatically use होते हैं
  • Test environment pre-configured होता है

Angular CLI Linting

ng lint

Explanation

  • Code quality check होती है
  • Best practices follow हो रही हैं या नहीं यह पता चलता है

Angular CLI Help Command

ng help

या specific command help:

ng g --help

Explanation

  • सभी available options दिखते हैं
  • Beginners के लिए बहुत useful है

Angular CLI Configuration File

Angular CLI configuration angular.json में होती है।

  • Build settings
  • Assets
  • Environments

इस file को advanced chapters में detail में cover किया जाएगा।

Common CLI Mistakes

  • CLI version mismatch
  • Global और local CLI confusion
  • Manual files create करना

Best Practices

  • CLI से ही files generate करें
  • Global CLI updated रखें
  • Project-specific CLI versions use करें
  • Manual configuration avoid करें

Summary

इस chapter में आपने सीखा:

  • Angular CLI क्या है और क्यों जरूरी है
  • Common CLI commands
  • Components और services generate करना
  • Build और test process