angluar-cli可以通过命令行快速的创建angluar项目
一、安装angluar-cli
你的电脑上需要安装nodeJs和 npm,使用 npm install -g @angular/cli 。安装完成后,你就可以使用ng命令
二、cli常用命令
1、创建应用
ng new my-app --style=scss
--style可以设置你应用使用的样式,默认是css,支持sass、scss、less、css
2、创建模块
ng g module app-routing [--flat ] [--module=app]
--flat把这个文件放进src/app 中,而不是单独的目录中, --module=app设置该模块注册到AppModule中的imports数组中,不需要你手动进行注册
3、创建组件
ng g component XXX
XXX为你的组件名,该命令会在当前module中创建组件,并会在module中注册该组件,如果你想要规定在哪个模块中注册,可以使用 --module=xxx来定义
4、创建服务
ng g service message
5、创建管道
ng g pipe date
6、动态组件
ng g directive test
7、运行应用
ng server --open --port 8888
默认地址为http://locahost:4200, 通过--port可以修改运行的端口
8、编译应用
ng build --prod --base-href ./
编译出的应用在根目录dist里面,--prod是将文件混淆、压缩、去掉不不需要的文件,--base-href ./是将应用的基本路径改为./,不然你的应用上传服务器且不在根路径就运行不了