Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure all modules are included in the stats file #21942

Merged
merged 2 commits into from
Feb 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions packages/next/build/webpack/plugins/build-stats-plugin.ts
Original file line number Diff line number Diff line change
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