前言
創(chuàng)新互聯(lián)公司是一家專業(yè)提供蒙自企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、H5建站、小程序制作等業(yè)務(wù)。10年已為蒙自眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進行中。前段時間將所負責的 Angular2 項目升級到了 Angular5 版本,這兩天又進行了升級至 Angular6 的嘗試??偟膩碚f,兩次升級過程比較類似,也不算復雜。
2018年5月4日,Angular6.0.0版正式發(fā)布,新版本主要關(guān)注底層框架和工具鏈,目的在于使其變得更小更快。
特性的小改動:
0. 項目特點
該項目有如下特點:
項目升級后也沒有使用 @angular/cli,繼續(xù)采用 fis3 作為編譯工具。這一是因為許多歷史悠久的代碼風格無法通過 tslint 校驗,ng build 根本無法執(zhí)行通過;二是因為項目的部分代碼編寫和構(gòu)建與發(fā)布流程使用了一些 fis3 的特性,改造成本較大。而且經(jīng)過比對,@angular/cli 的編譯過程并沒有比 fis3 好很多。
下面簡要介紹一下升級的過程和方法。
1. 更新 package.json 的依賴
將 Angular 依賴庫改為 ^6.1.0 版本,并且注意項目依賴的 Angular 組件庫的兼容版本更新。如我們的項目依賴有如下變更:
注意:一些組件庫的 API 也會有不兼容更新,相關(guān)代碼邏輯應(yīng)作改進(可在升級完成后根據(jù)文檔和錯誤提示去調(diào)試和修改)。
升級后的項目依賴參考:
{ "devDependencies": { "@compodoc/compodoc": "^1.1.5", "@lzwme/simple-mock": "~0.0.8", "@types/core-js": "^0.9.46", "@types/jasmine": "~2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "@types/webpack": "~2.2.14", "angular2-template-loader": "~0.6.2", "awesome-typescript-loader": "~3.2.3", "body-parser": "1.17.0", "cookie-parser": "1.4.3", "cross-env": "^5.1.6", "debug": "2.6.1", "ejs": "2.5.6", "express": "4.15.0", "fis-optimizer-htmlmin": "0.1.2", "fis-optimizer-png-compressor": "0.2.0", "fis-parser-less": "0.1.3", "fis-parser-pug": "0.0.1", "fis-postpackager-replace": "0.0.3", "fis3": "3.4.39", "fis3-deploy-local-supply": "0.0.2", "fis3-hook-commonjs": "0.1.27", "fis3-hook-node_modules": "2.3.1", "fis3-hook-relative": "2.0.3", "fis3-packager-deps-pack": "0.1.2", "fis3-parser-typescript": "^1.2.2", "fis3-postpackager-loader": "2.1.11", "fis3-preprocessor-cssprefixer": "0.0.2", "fis3-preprocessor-js-require-css": "0.1.3", "fis3-preprocessor-js-require-file": "0.1.3", "fis3-preprocessor-ng2-inline": "0.0.1", "fs-extra": "^6.0.1", "http-proxy": "1.16.2", "husky": "^0.14.3", "istanbul-instrumenter-loader": "^3.0.1", "jasmine-core": "^3.1.0", "karma": "^2.0.2", "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.1", "karma-coverage-istanbul-reporter": "^2.0.1", "karma-jasmine": "^1.1.2", "karma-jasmine-html-reporter": "^1.1.0", "karma-mocha-reporter": "^2.2.5", "karma-remap-coverage": "^0.1.5", "karma-sonarqube-unit-reporter": "^0.0.14", "karma-sourcemap-loader": "~0.3.7", "karma-webpack": "^3.0.0", "less": "^3.0.4", "less-loader": "^4.1.0", "liftoff": "2.3.0", "lint-staged": "^7.1.3", "minimist": "1.2.0", "morgan": "1.8.1", "prettier": "^1.13.5", "pug": "^2.0.3", "pug-html-loader": "^1.1.5", "raw-loader": "~0.5.1", "serve-favicon": "2.4.1", "stylelint": "^9.4.0", "stylelint-config-prettier": "^4.0.0", "supervisor": "^0.12.0", "to-string-loader": "^1.1.5", "tslint": "^5.10.0", "typedoc": "^0.11.1", "typescript": "^2.8.3", "webpack": "~3.6.0" }, "dependencies": { "@angular/animations": "^6.1.0", "@angular/common": "^6.1.0", "@angular/compiler": "^6.1.0", "@angular/core": "^6.1.0", "@angular/forms": "^6.1.0", "@angular/http": "^6.1.0", "@angular/platform-browser": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", "@ngrx/router-store": "6.1.0", "@ngrx/store": "^6.1.0", "@ngx-translate/core": "^10.0.2", "@ngx-translate/http-loader": "^3.0.0", "angular-tree-component": "^7.2.1", "buffer": "4.9.1", "core-js": "^2.5.7", "fis-mod": "1.0.1", "is-buffer": "1.1.4", "jquery": "1.12.4", "moment": "2.18.1", "ngrx-store-freeze": "0.2.4", "ngrx-store-logger": "0.2.2", "process": "0.11.9", "reflect-metadata": "0.1.12", "rxjs": "^6.0.0", "rxjs-compat": "^6.2.2", "throttle-debounce": "^2.0.1", "zone.js": "0.8.26" } }