Linux command
ng-new 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create a new Angular workspace
ng new [my-app]
Create without prompts
ng new [my-app] --defaults
Create with routing enabled
ng new [my-app] --routing
Create with specific style format
ng new [my-app] --style [scss|sass|less|css]
Create without initial git repository
ng new [my-app] --skip-git
Create without installing dependencies
ng new [my-app] --skip-install
Create as standalone
ng new [my-app] --standalone
Create in dry-run mode
ng new [my-app] --dry-run
说明
ng new creates a new Angular workspace and generates an initial application. It scaffolds the complete project structure including configuration files, source directories, and optionally installs npm dependencies. The command sets up TypeScript configuration, Angular-specific settings in angular.json, and testing infrastructure. The generated workspace follows Angular best practices and conventions. When run without the --defaults flag, the CLI prompts for routing preferences and stylesheet format. Since Angular 17, the command generates standalone components by default.
参数
- --routing
- Generate a routing module for the initial project.
- --style _STYLE_
- File extension for style files (css, scss, sass, less).
- --skip-git
- Do not initialize a git repository.
- --skip-install
- Do not install dependency packages.
- --skip-tests
- Do not generate spec files for the initial project.
- --standalone
- Create an application based on the standalone API without NgModules (default since Angular 17).
- --defaults
- Disable interactive prompts and use default values.
- --dry-run
- Run through without making changes (preview mode).
- --prefix _PREFIX_
- Prefix for generated selectors (default: app).
- --package-manager _PM_
- Package manager to use (npm, yarn, pnpm, cnpm).
- --directory _DIR_
- Directory to create the workspace in.
- --inline-style
- Include styles inline in the component TS file.
- --inline-template
- Include template inline in the component TS file.
- --view-encapsulation _MODE_
- View encapsulation strategy (Emulated, None, ShadowDom).
- --ssr
- Configure the application for Server-Side Rendering.
- --create-application
- When false, creates an empty workspace with no initial application.
- --help
- Display help information.
FAQ
What is the ng-new command used for?
ng new creates a new Angular workspace and generates an initial application. It scaffolds the complete project structure including configuration files, source directories, and optionally installs npm dependencies. The command sets up TypeScript configuration, Angular-specific settings in angular.json, and testing infrastructure. The generated workspace follows Angular best practices and conventions. When run without the --defaults flag, the CLI prompts for routing preferences and stylesheet format. Since Angular 17, the command generates standalone components by default.
How do I run a basic ng-new example?
Run `ng new [my-app]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --routing do in ng-new?
Generate a routing module for the initial project.