webpack/lib/optimize/FlagIncludedChunksPlugin.js

36 lines
1001 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
class FlagIncludedChunksPlugin {
apply(compiler) {
2017-12-06 22:01:25 +08:00
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", (compilation) => {
compilation.hooks.optimizeChunkIds.tap("FlagIncludedChunksPlugin", (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-04-21 16:05:56 +08:00
if(chunkA.getNumberOfModules() < chunkB.getNumberOfModules()) return;
2017-04-21 16:05:56 +08:00
if(chunkB.getNumberOfModules() === 0) return;
// is chunkB in chunkA?
for(const m of chunkB.modulesIterable) {
2017-04-21 16:05:56 +08:00
if(!chunkA.containsModule(m)) return;
}
chunkA.ids.push(chunkB.id);
});
});
});
});
}
}
module.exports = FlagIncludedChunksPlugin;