npm - Gitlab CI : npm doesn't like the cached node_modules

标签 npm gitlab npm-install gitlab-ci

互联网上充满了关于不缓存Gitlab的提示,但就我而言,我认为Gitlab CI确实可以正确缓存。关键是,npm似乎仍然会重新安装所有内容。

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - vendor/
    - bootstrap/
    - node_modules/

build-dependencies:
  image: ...
  stage: build
  script:
  - cp .env.gitlab-testing .env
  - composer install --no-progress --no-interaction
  - php artisan key:generate
  - npm install
  - npm run prod
  - npm run prod
  artifacts:
    paths:
    - vendor/
    - bootstrap/
    - node_modules/
    - .env
    - public/mix-manifest.json
  tags:
  - docker

这是我的gitlab-ci.yml文件(..相关部分)。虽然使用了缓存的 Composer 依赖关系,但没有使用node_modules。我什至添加了所有内容以绝望地缓存工件。

最佳答案

实际上它应该可以工作,您的缓存是全局设置的,您的键指向当前分支${CI_COMMIT_REF_SLUG} ...

这是我的构建,似乎在各个阶段之间缓存了node_modules。

image: node:latest

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
  - node_modules/
  - .next/

stages:
  - install
  - test
  - build
  - deploy

install_dependencies:
  stage: install
  script:
    - npm install

test:
  stage: test
  script:
    - npm run test

build:
  stage: build
  script:
    - npm run build

关于npm - Gitlab CI : npm doesn't like the cached node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55359804/

相关文章:

css - 每次保存文档时如何编译LESS文件?

node.js - npm WARN package.json Stock@0.0.1 没有存储库字段

node.js - 如何强制 npm 不创建指向本地包的符号链接(symbolic link)?

node.js - 如何使用 npx 从包运行 cli 命令而不进行全局安装

node.js - 无法在 Windows 的 NPM 脚本中使用 mkdir

npm - 错误 : Can't resolve 'stream' in . ... papaparse

javascript - rc 在配置文件的名称中代表什么?

deployment - 在 gitlab 中自动运行构建

docker - ci/cd中断go get测试

gitlab - 如何在 gitlab-ci 运行期间修复 "No such file or directory"