Reputation: 283
Im trying to cache my node_modules, and it works. Problem is that when I try to npm link some folder in node_modules, it just ignores changes, because its already cached.
So I want to exclude single folder, probably with regex, but after hours of googling stuff and reading documentation I just dont know how.
Problem:
When I change linked folder, app does not show changes, because its cached. And if cache
is set to false
, reaload takes long time.
Expectation
Be able to exclude single folder from caching in webpack, and still cache rest of node_modules. (I have tried using regex in immutablePaths
or managedPaths
)
here is my module.exports object:
{
...commonConfig.reactBundleConfig,
...{
mode: 'development',
watch: true,
watchOptions: {
ignored: ['ignored paths'],
followSymlinks: true
},
cache: {
type: 'filesystem'
},
devtool: 'source-map'
}
}
Upvotes: 6
Views: 1792
Reputation: 25287
I just set cache: false
until I am done making any potential changes to node_modules
.
After initially restarting my webpack-dev-server, I no longer have to restart my webpack server to see changes to files in my node_modules.
Upvotes: 0
Reputation: 1209
I think I got something. You should have a look at the cache.buildDependencies
option.
Quoted from the github page:
This is a new configuration option cache.buildDependencies, which allows specifying code dependencies of the build process. To make it easier webpack takes care of the resolving and following of dependencies of specified values.
There are two possible types of values: files and directories. Directories must end with a slash. Everything else is resolved as a file.
So I think if you add the buildDependencies
option to your cache config you could add some directories to it so webpack knows it needs those for the build.
It supposedly invalidates the persistent cache when anything in the directories you set changes.
I haven't tested it yet, but I think it should look something like this:
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename],
excludeThisThing: ["./node_modules/exclude/this/from/caching/"],
},
},
Upvotes: 0
Reputation: 41
You can use the next setting to exclude the module from caching:
snapshot: {
// https://github.com/webpack/webpack/issues/11952
managedPaths: [/^(.+?[\\/]node_modules)[\\/]((?!your-module-name)).*[\\/]*/],
}
Upvotes: 4