diff options
Diffstat (limited to 'node_modules/webpack/lib/CachePlugin.js')
-rw-r--r-- | node_modules/webpack/lib/CachePlugin.js | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/node_modules/webpack/lib/CachePlugin.js b/node_modules/webpack/lib/CachePlugin.js index 1b8d6a30e..9c19b8140 100644 --- a/node_modules/webpack/lib/CachePlugin.js +++ b/node_modules/webpack/lib/CachePlugin.js @@ -18,15 +18,31 @@ class CachePlugin { c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
});
} else {
- compiler.plugin("compilation", compilation => {
- if(!compilation.notCacheable) {
- compilation.cache = this.cache;
- } else if(this.watching) {
- compilation.warnings.push(
- new Error(`CachePlugin - Cache cannot be used because of: ${compilation.notCacheable}`)
- );
- }
- });
+ const registerCacheToCompiler = (compiler, cache) => {
+ compiler.plugin("this-compilation", compilation => {
+ // TODO remove notCacheable for webpack 4
+ if(!compilation.notCacheable) {
+ compilation.cache = cache;
+ compilation.plugin("child-compiler", (childCompiler, compilerName, compilerIndex) => {
+ if(cache) {
+ let childCache;
+ if(!cache.children) cache.children = {};
+ if(!cache.children[compilerName]) cache.children[compilerName] = [];
+ if(cache.children[compilerName][compilerIndex])
+ childCache = cache.children[compilerName][compilerIndex];
+ else
+ cache.children[compilerName].push(childCache = {});
+ registerCacheToCompiler(childCompiler, childCache);
+ }
+ });
+ } else if(this.watching) {
+ compilation.warnings.push(
+ new Error(`CachePlugin - Cache cannot be used because of: ${compilation.notCacheable}`)
+ );
+ }
+ });
+ };
+ registerCacheToCompiler(compiler, this.cache);
compiler.plugin("watch-run", (compiler, callback) => {
this.watching = true;
callback();
|