升级 Angular CLI 从1.7.3 到 6.0.1 时,遇到了以下 3 个难点

升级版本

    • Angular CLI で作成したプロジェクトの Angular CLI をバージョンアップした

 

    手順は こちら をトレースした

版本升级和迁移命令

$ cd target-project/
$ yarn add --dev @angular/cli@^6.0.1
$ ng update @angular/cli --migrate-only --from=1.7.3

发生的问题

1. 编译不通过 yì bù

yarn build を実行

$ yarn build
chunk {0} runtime.6afe30102d8fe7337431.js (runtime) 1.05 kB [entry] [rendered]
chunk {1} styles.e2ee1f7e974858d37595.css (styles) 45.3 kB [initial] [rendered]
chunk {2} polyfills.3a2cc09f9515a07bf722.js (polyfills) 59.1 kB [initial] [rendered]
chunk {3} main.555dba2cd512935e98e5.js (main) 490 kB [initial] [rendered]
Error: Expected to find an ngsw-config.json configuration file in the /Users/kasaharu/target-project folder. Either provide one or disable Service Worker in your angular.json configuration file.
Error: Error: Expected to find an ngsw-config.json configuration file in the /Users/kasaharu/target-project folder. Either provide one or disable Service Worker in your angular.json configuration file.
    • どうやら Service Worker の config ファイルが見つからなくなったらしい

同じ悩み を発見
下記の変更を入れることで解決

diff --git a/angular.json b/angular.json
index be4dab5..04bf825 100644
--- a/angular.json
+++ b/angular.json
@@ -42,7 +42,7 @@
               "vendorChunk": false,
               "buildOptimizer": true,
               "serviceWorker": true,
-              "ngswConfigPath": "/src/ngsw-config.json",
+              "ngswConfigPath": "src/ngsw-config.json",
               "fileReplacements": [
                 {
                   "replace": "src/environments/environment.ts",

2. 考试失败了

    • src/assets/styles/_mixin.scss を用意している

 

    stylePreprocessorOptions オプションを使って “includePaths”:[“src/assets/styles”] を指定している
$ yarn test
ERROR in ./src/app/app.component.scss
Module build failed:
@import 'mixin';
^
      File to import not found or unreadable: mixin.
      in /Users/kasaharu/target-project/src/app/app.component.scss (line 1, column 1)
 @ ./src/app/app.component.ts 18:21-52
 @ ./src/app/app.component.spec.ts
 @ ./src sync \.spec\.ts$
 @ ./src/test.ts
    • なぜか _mixin.scss の場所がわからなくなっている…

 

    やむおえず、相対パスでファイルを import することで解決

无法进行一次测试。

–single-run オプションがない

$ yarn test --single-run
Unknown option: '--singleRun'

据维基百科上的显示,似乎只剩下了 –watch=false 这个选项……因此要改成 –watch=false。

最后

yarn start –open で無事起動を確認

中国的本地参考链接

    • Angular CLI v1.7からv6.0へのマイグレーションについて (for v6.0.0-rc.2)

 

    • Angular Issue

 

    Angular CLI Wiki
bannerAds