Install
To install Angular CLI, you need to install node and npm first, and then a series of ng commands will be generated
ng new build project
Order | describe |
---|---|
ng new <project-name> [options] |
Create a new Angular project, default in the current directory |
Optional parameters:
parameter | describe |
---|---|
--dry-run -d |
Just output the file to be created and the action performed, no project is actually created |
--verbose -v |
output details |
--skip-npm |
Do not execute any npm commands when the project is first created |
--name |
Specify the name of the created project |
ng generate generates components/classes/pipelines/modules/routes, etc.
Order | describe |
---|---|
ng generate <type> [options] |
Build new code in the project |
ng g <type> [options] |
shorthand |
supported types | usage |
---|---|
Component | of g component my-new-component |
Directive | ng g directive my-new-directive |
Pipe | of g pipe my-new-pipe |
Service | of g service my-new-service |
Class | ng g class my-new-class |
Interface | ng g interface my-new-interface |
Enum | ng g enum my-new-enum |
Module | of g module my-module |
Route | of g route my-route当前已禁用 |
All built components will use their own directory unless --flat
specified separately.
parameter | describe |
---|---|
--flat |
Do not create code in your own directory |
--route=<route> |
Specifies the parent route. Only used to generate components and routes. Defaults to the specified path. |
--skip-router-generation |
Skip generating parent route configuration. Can only be used for routing commands. |
--default |
Specifies that the route should be the default route. |
--lazy |
Designated routes are deferred. Defaults to true. |
of build
Build artifacts will be stored in the /dist
directory.
ng build can specify a build target (--target=production or --target=development) and an environment file to use with the build (--environment=dev or --environment=prod). By default, the development build target and environment are used.
# 这是生产构建
ng build --target=production --environment=prod
ng build --prod --env=prod
ng build --prod
# 这是开发构建
ng build --target=development --environment=dev
ng build --dev --e=dev ng build --dev ng build