aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/optimize/FlagIncludedChunksPlugin.js
blob: e8b5a94577c304ebce130f587d201f3dcc2cda00 (plain)
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
/*
	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
						if(chunkA.modules.length < chunkB.modules.length) return;

						if(chunkB.modules.length === 0) return;

						// is chunkB in chunkA?
						for(let i = 0; i < chunkB.modules.length; i++) {
							if(chunkA.modules.indexOf(chunkB.modules[i]) < 0) return;
						}
						chunkA.ids.push(chunkB.id);
					});
				});
			});
		});
	}
}
module.exports = FlagIncludedChunksPlugin;