Skip to content

Commit

Permalink
Make sure all modules are included in the stats file (#21942)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Feb 7, 2021
1 parent e69a4d7 commit 44fa86e
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions packages/next/build/webpack/plugins/build-stats-plugin.ts
Expand Up @@ -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,
Expand All @@ -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 || reason.moduleId === module.id) {
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
}
Expand Down Expand Up @@ -94,6 +91,7 @@ export default class BuildStatsPlugin {
warnings: false,
maxModules: Infinity,
chunkModules: true,
modules: true,
// @ts-ignore this option exists
ids: true,
})
Expand Down

0 comments on commit 44fa86e

Please sign in to comment.