angular-cli,顾名思义,用于angular应用开发的脚手架,我们可以在命令行执行对应的命令。
- angular-cli主版本,跟angular保持一致。譬如angular9 → angular-cli 9
- 但是,子版本独立的。
@angular/cli@9.1.9
added 269 packages from 206 contributors in 77.894s
环境搭建
安装
1 | npm install -g @angular/cli |
卸载
1 | npm uninstall -g @angular/cli |
校验
1 | > ng v |
cli命令介绍
ng 命令列表
1.add
Adds support for an external library to your project.
2.analytics
Configures the gathering of Angular CLI usage metrics. See https://angular.io/cli/usage-analytics-gathering.
3.build(b)
Compiles an Angular app into an output directory named dist/ at the given output path. Must be executed from within a workspace directory.
4.deploy
Invokes the deploy builder for a specified project or for the default project in the workspace.
5.config
Retrieves or sets Angular configuration values in the angular.json file for the workspace.
6.doc (d)
Opens the official Angular documentation (angular.io) in a browser, and searches for a given keyword.
7.e2e (e)
Builds and serves an Angular app, then runs end-to-end tests using Protractor.
8.generate (g)
Generates and/or modifies files based on a schematic.
ng g [schematic] [options]
schematic 列表如下(=== options均以两个-分隔 === ):
appShell
- ss
application
- ss
class - 产生新的ts文件
- ng g class [name] [options]
- ng g class classTest –lintFix=true # 文件创建后,应用lint fix功能
1 | # 得到如下ts文件 |
- ng g class classTest –project=projectTest # 设置项目名
- ng g class classTest –skipTests=true #不创建spec.ts的测试文件
- ng g class classTest –type=model # 修改ts,形如 classTest.model.ts
1 | > ng g class --type=model |
component
- ng g c [name] [options]
- ng g c user –prefix=we # 指定组件的选择器
- ng g c user –selector=idata # 指定组件的选择器前缀
- ng g c user –export=true # 导出组件
1 | > ng g c user --selector=idata --prefix=we --export=true |
directive
- ng g d [name] [options]
enum
- ng g e [name] [options]
guard
interceptor
interface
- ng g i [name] [options]
library
module
pipe
- ng g p [name] [options]
service
- ng g s [name] [options]
serviceWorker
webWorker
9.help
Lists available commands and their short descriptions.
10.lint (l)
Runs linting tools on Angular app code in a given project folder.
11.new (n)
Creates a new workspace and an initial Angular app.
ng n
- 创建新的angular工程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16$ ng n my-first-project
? Would you like to add Angular routing? Yes
? Which stylesheet format would you like to use? SCSS ]
CREATE angular-demo/README.md (1028 bytes)
CREATE angular-demo/.editorconfig (274 bytes)
CREATE angular-demo/.gitignore (631 bytes)
CREATE angular-demo/angular.json (3702 bytes)
CREATE angular-demo/package.json (1254 bytes)
CREATE angular-demo/tsconfig.json (489 bytes)
CREATE angular-demo/tslint.json (3125 bytes)
CREATE angular-demo/browserslist (429 bytes)
CREATE angular-demo/karma.conf.js (1024 bytes)
CREATE angular-demo/tsconfig.app.json (210 bytes)
.....
Packages installed successfully.
Successfully initialized git.
12.run
Runs an Architect target with an optional custom builder configuration defined in your project.
13.serve (s)
Builds and serves your app, rebuilding on file changes.
14.test (t)
Runs unit tests in a project.
15.update
Updates your application and its dependencies. See https://update.angular.io/
16.version (v)
Outputs Angular CLI version.
17.xi18n (i18n-extract)
Extracts i18n messages from source code.
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏