Angular-cli 搭建项目

一、首先需要安装nodenpm

  查看你的node以及npm版本:

  node -v 查看node版本

  npm -v 查看npm版本

  要求所有版本都是最新的,不然可能会出错。

  设置淘宝镜像,这样下载东西就是从国内网站下载了,网速更快

   npm install cnpm -g --registry=https://registry.npm.taobao.org  安装cnpm

npm configset registry https://registry.npm.taobao.org

二、安装typescript和typings

npm install -g typescript typings

三、安装angular-cli

npm install -g @angular/cli

npm install -g angular-cli@latest

 安装完成后,ng -v 出现以下界面说明安装成功了

四、如果你之前安装失败过,最好在安装angular-cli之前先卸载干净,用以下命令

 npm uninstall -g angular-cli
 npm cache clean

五、如果出现node-sass解析失败问题,用淘宝镜像安装cnpm。安装完node-sass之后再安装angular-cli,就没问题了

npm install -g cnpm --registry=https://registry.npm.taobao.org

npm install node-sass --save-dev

六、创建项目(-skip-install直接跳过下载)

ng new myapp —skip-install

七、运行项目

cd myapp
npm install
ng serve

八、创建组件(不生成spec.ts文件)

ng generate component my-component --no-spec

原文地址:https://www.cnblogs.com/le220/p/12720509.html