Webpack config cache.buildDependencies can be used to list files or directories, such that if they change then the filesystem-based webpack build cache is invalidated.
This is documented in depth at the persistent caching guide.
The doc says the webpack lib is included by default. Doc also shows how to include the webpack.config.js file itself.
Is it a stupid question to ask, how about node_modules? They don't mention anything like yarn.lock either. In some kinds of workspaces lib dependencies may appear in node_modules as symlinks - in those cases the dependency can be updated in parallel during development. Those changes should invalidate these webpack build caches right?