forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlagIncludedChunksPlugin.js
More file actions
38 lines (34 loc) · 1.05 KB
/
FlagIncludedChunksPlugin.js
File metadata and controls
38 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
class FlagIncludedChunksPlugin {
apply(compiler) {
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;
// 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;
if (chunkB.getNumberOfModules() === 0) continue loopB;
// is chunkB in chunkA?
for (const m of chunkB.modulesIterable) {
if (!chunkA.containsModule(m)) continue loopB;
}
chunkA.ids.push(chunkB.id);
}
}
}
);
});
}
}
module.exports = FlagIncludedChunksPlugin;