Evan Carroll
Evan Carroll

Reputation: 1

NPM and CI: --cache vs node_modules/

With GitLab I can cache node_modules/ and/or I can cache the argument to npm ci --cache <dir>

What's the difference between these two options?

The GitLab docs show:

npm ci --cache .npm --prefer-offline

But they don't explain why I would not want to cache node_modules/.

Size difference:

❯ du -hs .npm
136M    .npm
❯ du -hs node_modules
932M    node_modules

Upvotes: 5

Views: 4366

Answers (1)

Evan Carroll
Evan Carroll

Reputation: 1

The difference in my case was massive, by NOT caching node_modules/ I reduced my CI pipeline timing between 30-50%.

It's faster to have every stage include

npm ci --cache .npm --prefer-offline

Then it is to move around node_modules/ with a GitLab cache layer.

I suppose the data may work out differently if not using containerized runners.

Upvotes: 3

Related Questions