Whats the correct cache key for webpack build on CI (cache invalidation)?

Viewed 187

Caching on the CI is important. It speeds up the build and reduces costs.

It's very popular for speeding up npm install. People are caching the node_modules directory or the npm/yarn cache across builds. (the internet will tell you how that works)

Finding the correct cache key for working with node_modules is fairly easy: it's the hash of the lock file. If something in the lock file changes, it generates a new hash and the cache is "invalidated".

I'm trying to persist the webpack build cache. This is possible with persistent caching in webpack 5. Setting up the cache is easy, find the "correct" strategy to generate the cache key I find hard.

Lock file hash is certainly doesn't work. Stuff will change without lock file being touched.

I was thinking about creating a new cache entry every time something is merged to master/main using the commit hash as key. Then, when a feature branch is created, it can use this commit hash as cache key.

What is the best way to cache webpack builds on CI?

0 Answers
Related