安装angular脚手架
npm install -g @angular/cli 或 yarn add global @angular/cli
ng v 查看版本,是否安装成功
1. 新建项目
我选择的less预处理器;
ng new projectName
cd projectName
ng add ng-zorro-antd
ng serve :运行项目;
socket.io:file(src->polyfills.ts):(window as any).goobal = window;
路由懒加载模式:
创建路由组建:
ng g module routesFile/ --routing
ng g c routesFile/
配置代理:
新建 proxyconfig.json文件
{
"/api": {
"target": "目标域名",
"secure": false,
"logLevel": "debug",
"changeOrigin": true,
"pathRewrite": {
"/api": "/api"
}
}
}
anjular.json文件中引用:
projects:{
'项目名称':{
architect: {
serve: {
"options": {
"browserTarget": "system:build",
"proxyConfig": "proxyconfig.json", // 加入
}
},
}
}
}
}
项目打包:
ng build 打包项目
ng build --prod 自动调用aot打包