# ng6升级至ng10
# 1. 当前环境(升级后)

# 2. 升级node
下载最新安装包重新安装
https://nodejs.org/zh-cn/download/
# 3. 升级angular-cli
## 卸载原angular-cli
npm uninstall -g @angualr/cli
npm cache clean --force
#全局安装最新版cli
npm install -g @angular/cli
1
2
3
4
5
6
2
3
4
5
6
# 4. 使用公司内部npm私服
## 拷贝一下内容到 C:\Users\administrator\.npmrc 文件中
registry=http://192.168.195.95:8888/repository/npm-group/
always-auth=true
_auth="ZGVwbG95ZXI6ZGVwbG95ZXI="
//192.168.195.95:8888/repository/npm-group/:_authToken=NpmToken.80b3af5b-c05a-3569-b259-ba716af1891c
1
2
3
4
5
2
3
4
5
# 5. 运行命令,启动更新程序,查看需要更新的依赖:
cd demo-webapp\web
ng update
1
2
2
# 6. 强制升级
ng update --all --force
1
# 7. 升级后修改点:
# 7.1 配置文件
# 以下文件移入 web 目录,参考报告教师PC端或学生PC端
- tsconfig.json
- tsconfig.app.json
- tsconfig.base.json
- tsconfig.spec.json
- .browserslistrc
- karma.conf.js
# 修改angular.json文件,参考报告教师PC端或学生PC端
# 7.2 代码( 哪里报错改哪里 )
# 7.3 特别注意
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: 'login',
loadChildren: () => import('./login/login.module').then(m => m.LoginModule)
},
{
path: 'index',
loadChildren: () => import('./index/index.module').then(m => m.IndexModule)
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
完成后最新目录如下:

# 常见问题解决
# 解决启动时警告:
depends on 'jquery'. CommonJS or AMD dependencies can cause optimization bailouts.
1
# 解决:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/web",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
...
],
"styles": [
...
],
"scripts": [
...
],
"allowedCommonJsDependencies": [ // 允许 CommonJs 依赖
"jquery",
"echarts",
"zrender/lib/svg/svg",
"zrender/lib/vml/vml"
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26