123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- "use strict";
- class FlagIncludedChunksPlugin {
-
- apply(compiler) {
- compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {
- compilation.hooks.optimizeChunkIds.tap(
- "FlagIncludedChunksPlugin",
- chunks => {
- const chunkGraph = compilation.chunkGraph;
-
-
-
-
-
-
-
-
-
-
-
-
- const moduleBits = new WeakMap();
- const modulesCount = compilation.modules.size;
-
- const modulo = 1 / Math.pow(1 / modulesCount, 1 / 31);
- const modulos = Array.from(
- { length: 31 },
- (x, i) => Math.pow(modulo, i) | 0
- );
-
- let i = 0;
- for (const module of compilation.modules) {
- let bit = 30;
- while (i % modulos[bit] !== 0) {
- bit--;
- }
- moduleBits.set(module, 1 << bit);
- i++;
- }
-
-
- const chunkModulesHash = new WeakMap();
- for (const chunk of chunks) {
- let hash = 0;
- for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
- hash |= (moduleBits.get(module));
- }
- chunkModulesHash.set(chunk, hash);
- }
- for (const chunkA of chunks) {
- const chunkAHash =
-
- (chunkModulesHash.get(chunkA));
- const chunkAModulesCount =
- chunkGraph.getNumberOfChunkModules(chunkA);
- if (chunkAModulesCount === 0) continue;
- let bestModule = undefined;
- for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
- if (
- bestModule === undefined ||
- chunkGraph.getNumberOfModuleChunks(bestModule) >
- chunkGraph.getNumberOfModuleChunks(module)
- )
- bestModule = module;
- }
- loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
- (bestModule)
- )) {
-
-
- if (chunkA === chunkB) continue;
- const chunkBModulesCount =
- chunkGraph.getNumberOfChunkModules(chunkB);
-
- if (chunkBModulesCount === 0) continue;
-
-
- if (chunkAModulesCount > chunkBModulesCount) continue;
-
-
- const chunkBHash =
-
- (chunkModulesHash.get(chunkB));
- if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
-
- for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
- if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
- }
-
- (chunkB.ids).push( (chunkA.id));
- }
- }
- }
- );
- });
- }
- }
- module.exports = FlagIncludedChunksPlugin;
|