我需要在 CI 作业中缓存什么以避免每次 ngcc 重新编译?

max*_*pre 45 continuous-integration circleci angular angular-ivy angular9

使用 angular 9 和它的新编译引擎 IVY,我的 CI 构建时间大幅增加。这当然是因为ngcc它在许多模块上运行。

例如

Compiling @angular/core : es2015 as esm2015

Compiling @angular/common : es2015 as esm2015

...
Run Code Online (Sandbox Code Playgroud)

我以为ngcc缓存在编译的库node_modules,但我的node_modules缓存在我的CI工作,还有编的现象发生,所以这是不可能的。

我应该缓存什么路径以避免ngcc在每次构建时重新编译所有模块?

tra*_*mer 1

更新1:

如果您使用的是最新版本,则硬编码Ivy entry点已从角度构建中删除wrongly hardcoded,它位于之前和内部Angular init TS github code link

现在/最近你可以这样做

ngcc --properties es2015 browser module main



仅适用于旧版本,请参阅更新 1 了解新版本

ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points

或者作为你内部建造的一部分package.json

{  
  "scripts": {    
    "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
  }
}
Run Code Online (Sandbox Code Playgroud)

一些参考将Travis 配置为

# custom caching for .travis.yml
install:
- npm ci
# keep the npm cache around to speed up installs
cache:
  directories:
  - "$HOME/.npm"
# you can add other 
Run Code Online (Sandbox Code Playgroud)

选项 2:使用yarn 或 pnpm 速度更快

pnpm install
// or
yarn install
// or
npm install --prefer-offline --no-audit
Run Code Online (Sandbox Code Playgroud)