You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular CLI缓存在GitHub Actions与本地环境表现差异的问题求助

Angular CLI缓存在GitHub Actions与本地环境表现差异的问题求助

大家好,我遇到了Angular CLI缓存在GitHub Actions里表现异常的问题,想请各位帮忙分析下:

我已经在.angular.json中启用了缓存配置,具体内容如下:

"cli": {
  "cache": {
    "enabled": true,
    "environment": "all"
  }
}

同时在GitHub Actions的Workflow里配置了对.angular文件夹的缓存,对应的步骤代码是:

steps:
  - name: Cache Angular build
    uses: actions/cache@v3
    id: cache-build
    env:
      cache-name: cache-build
    with:
      path: .angular
      key: ${{ runner.OS }}-build${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}

  - name: Create Build
    shell: bash
    run: |
      ls -la .angular/cache
      npm run build ${{ inputs.product }} -- --configuration=${{ inputs.angularConfig }} --output-path=${{ inputs.buildPath }}

现在的问题是:带缓存的CI构建耗时大约6分钟,不带缓存的话是7分钟左右;但在本地环境,带缓存构建只需要不到1分钟,不带缓存才会用到6分钟,两者差距特别大。

为了排查问题,我在同一个Workflow里连续执行了两次构建:

- name: Create Build
  shell: bash
  run: |
    npm run build ${{ inputs.product }} -- --configuration=${{ inputs.angularConfig }} --output-path=${{ inputs.buildPath }}

- name: Create Build 2
  shell: bash
  run: |
    npm run build ${{ inputs.product }} -- --configuration=${{ inputs.angularConfig }} --output-path=${{ inputs.buildPath }}

结果第二次构建的耗时居然只有1分钟!这让我怀疑Angular CLI的缓存可能不全在.angular文件夹里,是不是还有一部分存在~/目录或者其他路径?有没有朋友遇到过类似的情况,或者有什么排查思路?

我期望CI环境的构建耗时能和本地环境差不多,毕竟缓存的作用就是大幅缩短重复构建的时间。

备注:内容来源于stack exchange,提问作者Vahid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 10:24:35