Commit a61aa55f authored by Marcel Amirault's avatar Marcel Amirault

Merge branch 'docs/ci-use-npm-good-practice-in-example' into 'master'

docs: Change Node.js npm dependencies install in caching example

See merge request gitlab-org/gitlab!25758
parents 7caea10b fc5fecda
...@@ -206,10 +206,11 @@ templates](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/lib/gitlab/ci/t ...@@ -206,10 +206,11 @@ templates](https://gitlab.com/gitlab-org/gitlab-foss/tree/master/lib/gitlab/ci/t
### Caching Node.js dependencies ### Caching Node.js dependencies
Assuming your project is using [npm](https://www.npmjs.com/) or Assuming your project is using [npm](https://www.npmjs.com/) to install the Node.js
[Yarn](https://classic.yarnpkg.com/en/) to install the Node.js dependencies, the dependencies, the following example defines `cache` globally so that all jobs inherit it.
following example defines `cache` globally so that all jobs inherit it. By default, npm stores cache data in the home folder `~/.npm` but since
Node.js modules are installed in `node_modules/` and are cached per-branch: [you can't cache things outside of the project directory](../yaml/README.md#cachepaths),
we tell npm to use `./.npm` instead, and it is cached per-branch:
```yaml ```yaml
# #
...@@ -221,10 +222,10 @@ image: node:latest ...@@ -221,10 +222,10 @@ image: node:latest
cache: cache:
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
paths: paths:
- node_modules/ - .npm/
before_script: before_script:
- npm install - npm ci --cache .npm --prefer-offline
test_async: test_async:
script: script:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment