webpack/lib/optimize/FlagIncludedChunksPlugin.js

39 lines
1.1 KiB
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) {
2018-02-25 09:00:20 +08:00
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {
compilation.hooks.optimizeChunkIds.tap(
"FlagIncludedChunksPlugin",
chunks => {
for (const chunkA of chunks) {
loopB: for (const chunkB of chunks) {
// as we iterate the same iterables twice
// skip if we find ourselves
if (chunkA === chunkB) continue loopB;
2018-02-25 09:00:20 +08:00
// instead of swapping A and B just bail
// as we loop twice the current A will be B and B then A
if (chunkA.getNumberOfModules() < chunkB.getNumberOfModules())
continue loopB;
2018-02-25 09:00:20 +08:00
if (chunkB.getNumberOfModules() === 0) continue loopB;
2018-02-25 09:00:20 +08:00
// is chunkB in chunkA?
for (const m of chunkB.modulesIterable) {
if (!chunkA.containsModule(m)) continue loopB;
}
chunkA.ids.push(chunkB.id);
}
2018-01-22 20:52:43 +08:00
}
}
2018-02-25 09:00:20 +08:00
);
});
}
}
module.exports = FlagIncludedChunksPlugin;