Linux command
angular 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create a new Angular workspace
ng new [project-name]
Serve the application
ng serve
Serve on a specific port
ng serve --port [4200] --open
Generate a new component
ng generate component [component-name]
Generate a service
ng generate service [service-name]
Build the application
ng build --configuration production
Run unit tests
ng test
Run end-to-end tests
ng e2e
说明
ng is the command-line interface for Angular, a platform for building web applications. It provides tools for creating projects, generating code, building, testing, and deploying Angular applications. The CLI automates common development tasks through schematics - templates that generate boilerplate code for components, services, modules, and other Angular constructs. The generate command supports creating components, directives, pipes, services, classes, guards, interfaces, enums, and modules. Projects are configured through angular.json, which defines build targets, file paths, and environment-specific settings. The CLI supports multiple projects within a single workspace, enabling monorepo-style development. The serve command provides a development server with hot module replacement, automatically rebuilding and refreshing the browser when source files change. Production builds use build --configuration production which enables optimizations like ahead-of-time compilation, tree shaking, and minification.
参数
- new (alias: n)
- Create a new Angular workspace and initial application
- serve (alias: s, dev)
- Build and serve the application with live reload on file changes
- generate (alias: g)
- Generate components, services, modules, pipes, directives, and other schematics
- build (alias: b)
- Compile the application into the dist/ output directory
- test (alias: t)
- Run unit tests using the configured test runner
- e2e (alias: e)
- Build, serve, and run end-to-end tests
- lint
- Run linting tools on the application code
- add
- Add support for an external library (installs and configures packages)
- update
- Update the workspace and its dependencies
- deploy
- Invoke the deploy builder for the project
- config
- Get or set configuration values in angular.json
- cache
- Configure and manage the persistent disk cache
- version (alias: v)
- Display Angular CLI version information
- analytics
- Configure anonymous telemetry settings for the Angular CLI
- completion
- Set up Angular CLI shell autocompletion
- run
- Run an Architect target in the workspace (e.g. my-project:build)
- extract-i18n
- Extract i18n messages from the source code
- --help
- Display help for any command
- --dry-run
- Preview changes without writing files
- --verbose
- Enable verbose logging output
- --force
- Force overwriting of existing files (generators)
FAQ
What is the angular command used for?
ng is the command-line interface for Angular, a platform for building web applications. It provides tools for creating projects, generating code, building, testing, and deploying Angular applications. The CLI automates common development tasks through schematics - templates that generate boilerplate code for components, services, modules, and other Angular constructs. The generate command supports creating components, directives, pipes, services, classes, guards, interfaces, enums, and modules. Projects are configured through angular.json, which defines build targets, file paths, and environment-specific settings. The CLI supports multiple projects within a single workspace, enabling monorepo-style development. The serve command provides a development server with hot module replacement, automatically rebuilding and refreshing the browser when source files change. Production builds use build --configuration production which enables optimizations like ahead-of-time compilation, tree shaking, and minification.
How do I run a basic angular example?
Run `ng new [project-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does new (alias: n) do in angular?
Create a new Angular workspace and initial application