123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- "use strict";
- class MergeDuplicateChunksPlugin {
- apply(compiler) {
- compiler.hooks.compilation.tap(
- "MergeDuplicateChunksPlugin",
- compilation => {
- compilation.hooks.optimizeChunksBasic.tap(
- "MergeDuplicateChunksPlugin",
- chunks => {
-
- const notDuplicates = new Set();
-
- for (const chunk of chunks) {
-
- let possibleDuplicates;
- for (const module of chunk.modulesIterable) {
- if (possibleDuplicates === undefined) {
-
-
-
- for (const dup of module.chunksIterable) {
- if (
- dup !== chunk &&
- chunk.getNumberOfModules() === dup.getNumberOfModules() &&
- !notDuplicates.has(dup)
- ) {
-
- if (possibleDuplicates === undefined) {
- possibleDuplicates = new Set();
- }
- possibleDuplicates.add(dup);
- }
- }
-
- if (possibleDuplicates === undefined) break;
- } else {
-
- for (const dup of possibleDuplicates) {
-
- if (!dup.containsModule(module)) {
- possibleDuplicates.delete(dup);
- }
- }
-
- if (possibleDuplicates.size === 0) break;
- }
- }
-
- if (
- possibleDuplicates !== undefined &&
- possibleDuplicates.size > 0
- ) {
- for (const otherChunk of possibleDuplicates) {
- if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
-
- if (chunk.integrate(otherChunk, "duplicate")) {
- chunks.splice(chunks.indexOf(otherChunk), 1);
- }
- }
- }
-
- notDuplicates.add(chunk);
- }
- }
- );
- }
- );
- }
- }
- module.exports = MergeDuplicateChunksPlugin;
|