package.json中Angular 2到4迁移的更改

use*_*978 5 angularjs angular4 angular

目前,该应用程序是在Angular 2.0.0上.为了与Angular 4兼容,需要更改哪些包或依赖项?到目前为止,我改变了以下内容,

"dependencies": {
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@angular/router": "4.0.0",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "4.0.0",
"angular2-toaster": "2.0.0",
"rxjs": "^5.0.1",
"typescript": "^2.1.5",
"zone.js": "^0.8.4"
}
Run Code Online (Sandbox Code Playgroud)

是否还有其他需要更改的包/依赖项?

我应该更改tsconfig.json吗?

{


 "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "lib": [
      "es5",
      "es2015",
      "es2017",
      "dom",
      "scripthost"
    ],
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "allowNonTsExtensions" : true
  },
  "exclude": [
    "node_modules",
    "typings/main.d.ts",
    "typings/main"
  ],
  "filesGlob": [
    "./src/**/*.ts",
    "./test/**/*.ts",
    "!./node_modules/**/*.ts",
    "src/custom_typings.d.ts",
    "typings/browser.d.ts"
  ],
  "awesomeTypescriptLoaderOptions": {
    "resolveGlobs": true,
    "forkChecker": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": { "rewriteTsconfig": false }
}
Run Code Online (Sandbox Code Playgroud)

小智 0

您不需要更改 ts.config。您在 package.json 中所做的更改似乎是正确的。

几点:

  • 我认为“typescript”应该位于“devDependency”中,因为在生产模式下您不需要它。
  • 我建议从所有依赖项中删除“^”,因为最好锁定确切的版本
  • 我还强烈建议使用“shrinkwrap”来避免依赖项中松散的依赖项。

要安装 Angular 最新版本,请删除/移动当前的 node_modules 文件夹。然后:

npm cache clean
npm install
Run Code Online (Sandbox Code Playgroud)

有关参考,请参阅“更新到 4.0.0”部分 http://angularjs.blogspot.com/2017/03/angular-400-now-available.html