angular - 我需要在 CI 作业中缓存什么以避免每次 ngcc 重新编译?
问题描述
有了 Angular 9 和它的新编译引擎 IVY,我的 CI 构建时间大大增加了。这当然是因为ngcc
在许多模块上运行。
例如
Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
...
我以为ngcc
将已编译的库缓存在 中node_modules
,但我node_modules
的缓存在我的 CI 作业中,并且仍在进行编译,所以不可能。
我应该缓存什么路径以避免ngcc
在每次构建时重新编译所有模块?
解决方案
更新 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" } }
一些参考将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
选项 2:使用 yarn 或 pnpm 更快
pnpm install
// or
yarn install
// or
npm install --prefer-offline --no-audit