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 FlagIncludedChunksPlugin {
|
|
|
|
|
|
|
|
apply(compiler) {
|
|
|
|
compiler.plugin("compilation", (compilation) => {
|
|
|
|
compilation.plugin("optimize-chunk-ids", (chunks) => {
|
|
|
|
chunks.forEach((chunkA) => {
|
|
|
|
chunks.forEach((chunkB) => {
|
|
|
|
// as we iterate the same iterables twice
|
|
|
|
// skip if we find ourselves
|
|
|
|
if(chunkA === chunkB) return;
|
|
|
|
|
|
|
|
// instead of swapping A and B just bail
|
|
|
|
// as we loop twice the current A will be B and B then A
|
2017-08-14 05:01:11 +02:00
|
|
|
if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return;
|
2017-05-03 15:35:00 +02:00
|
|
|
|
2017-08-14 05:01:11 +02:00
|
|
|
if(chunkB.getNumberOfModules() === 0) return;
|
2017-05-03 15:35:00 +02:00
|
|
|
|
|
|
|
// is chunkB in chunkA?
|
2017-08-14 05:01:11 +02:00
|
|
|
for(const m of chunkB.modulesIterable) {
|
|
|
|
if(!chunkA.containsModule(m)) return;
|
2017-05-03 15:35:00 +02:00
|
|
|
}
|
|
|
|
chunkA.ids.push(chunkB.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = FlagIncludedChunksPlugin;
|