2017-05-03 15:35:00 +02:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class EnsureChunkConditionsPlugin {
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.plugin("compilation", (compilation) => {
|
2017-08-14 05:01:11 +02:00
|
|
|
const triesMap = new Map();
|
2017-05-03 15:35:00 +02:00
|
|
|
compilation.plugin(["optimize-chunks-basic", "optimize-extracted-chunks-basic"], (chunks) => {
|
|
|
|
let changed = false;
|
|
|
|
chunks.forEach((chunk) => {
|
2017-08-14 05:01:11 +02:00
|
|
|
chunk.forEachModule((module) => {
|
2017-05-03 15:35:00 +02:00
|
|
|
if(!module.chunkCondition) return;
|
|
|
|
if(!module.chunkCondition(chunk)) {
|
2017-08-14 05:01:11 +02:00
|
|
|
let usedChunks = triesMap.get(module);
|
|
|
|
if(!usedChunks) triesMap.set(module, usedChunks = new Set());
|
|
|
|
usedChunks.add(chunk);
|
2017-05-03 15:35:00 +02:00
|
|
|
const newChunks = [];
|
|
|
|
chunk.parents.forEach((parent) => {
|
2017-08-14 05:01:11 +02:00
|
|
|
if(!usedChunks.has(parent)) {
|
2017-05-03 15:35:00 +02:00
|
|
|
parent.addModule(module);
|
2017-10-14 18:40:54 +02:00
|
|
|
module.addChunk(parent);
|
2017-05-03 15:35:00 +02:00
|
|
|
newChunks.push(parent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
module.rewriteChunkInReasons(chunk, newChunks);
|
|
|
|
chunk.removeModule(module);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if(changed) return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = EnsureChunkConditionsPlugin;
|