From 56938728896475390a7df3242b8a023f5ce50c62 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 7 Feb 2021 17:44:22 +0100 Subject: [PATCH 1/2] Make sure all modules are included in the stats file --- .../webpack/plugins/build-stats-plugin.ts | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/next/build/webpack/plugins/build-stats-plugin.ts b/packages/next/build/webpack/plugins/build-stats-plugin.ts index 26d4918676071..9d7cc674aab09 100644 --- a/packages/next/build/webpack/plugins/build-stats-plugin.ts +++ b/packages/next/build/webpack/plugins/build-stats-plugin.ts @@ -9,7 +9,6 @@ import { tracer, traceAsyncFn } from '../../tracer' const STATS_VERSION = 0 function reduceSize(stats: any) { - const modules = new Map() stats.chunks = stats.chunks.map((chunk: any) => { const reducedChunk: any = { id: chunk.id, @@ -18,47 +17,45 @@ function reduceSize(stats: any) { } for (const module of chunk.modules) { - if (!module.name) { + if (!module.id) { continue } - const reducedModule: any = { - type: module.type, - moduleType: module.moduleType, - size: module.size, - name: module.name, + if (!reducedChunk.modules) { + reducedChunk.modules = [] } - if (module.reasons) { - for (const reason of module.reasons) { - if (!reason.name) { - continue - } + reducedChunk.modules.push(module.id) + } - if (!reducedModule.reasons) { - reducedModule.reasons = [] - } + return reducedChunk + }) + + stats.modules = stats.modules.map((module: any) => { + const reducedModule: any = { + type: module.type, + moduleType: module.moduleType, + size: module.size, + name: module.name, + } - reducedModule.reasons.push({ - id: reason.id, - }) + if (module.reasons) { + for (const reason of module.reasons) { + if (!reason.moduleName) { + continue } - } - modules.set(module.id, reducedModule) + if (!reducedModule.reasons) { + reducedModule.reasons = [] + } - if (!reducedChunk.modules) { - reducedChunk.modules = [] + reducedModule.reasons.push(reason.moduleId) } - - reducedChunk.modules.push(module.id) } - return reducedChunk + return [module.id, reducedModule] }) - stats.modules = [...modules.entries()] - for (const entrypointName in stats.entrypoints) { delete stats.entrypoints[entrypointName].assets } @@ -94,6 +91,7 @@ export default class BuildStatsPlugin { warnings: false, maxModules: Infinity, chunkModules: true, + modules: true, // @ts-ignore this option exists ids: true, }) From a4f4e8f5cece3fbd7183595afdecbaf6ef9b71e7 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 7 Feb 2021 18:16:40 +0100 Subject: [PATCH 2/2] Don't include module's own module id in reasons for module being used --- packages/next/build/webpack/plugins/build-stats-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/build/webpack/plugins/build-stats-plugin.ts b/packages/next/build/webpack/plugins/build-stats-plugin.ts index 9d7cc674aab09..bc8a6daf4c918 100644 --- a/packages/next/build/webpack/plugins/build-stats-plugin.ts +++ b/packages/next/build/webpack/plugins/build-stats-plugin.ts @@ -41,7 +41,7 @@ function reduceSize(stats: any) { if (module.reasons) { for (const reason of module.reasons) { - if (!reason.moduleName) { + if (!reason.moduleName || reason.moduleId === module.id) { continue }