Skip to content

Commit

Permalink
Dont show stats for bootstrap/runtime bundles. Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maier49 committed Apr 25, 2020
1 parent 00b5aec commit bd6cc17
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 123 deletions.
45 changes: 24 additions & 21 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,46 @@ export default function logger(stats: any, config: any, runningMessage: string =
let chunks: undefined | string[];

let chunkMap: { [chunk: string]: any };
const excludeChunks = /(^bootstrap$)|(^runtime\/)/;
if (args.mode === 'dist') {
chunkMap = analyzeBundles(stats, config, {
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: true,
reportFilename: '../info/report.html',
statsFilename: '../info/stats.json',
excludeBundles: '(^bootstrap.)|(^runtime/)'
excludeBundles: '(^bootstrap\\.)|(^runtime/)'
});
}
chunks = (Array.isArray(config)
? loggerStats.children.reduce((chunks: any[], current: any) => [...chunks, ...current.chunks], [])
: loggerStats.chunks
).map((chunk: any) => {
const chunkName: string = chunk.names[0];
if (!chunkMap) {
return chunkName;
} else {
const chunkStats = chunkMap[chunkName];
const size = ((chunkStats && (chunkStats.parsedSize || chunkStats.statSize)) || 0) / 1000;
const gzipSize = ((chunkStats && chunkStats.gzipSize) || 0) / 1000;
)
.filter((chunk: any) => !excludeChunks.test(chunk.names[0] || ''))
.map((chunk: any) => {
const chunkName: string = chunk.names[0];
if (!chunkMap) {
return chunkName;
} else {
const chunkStats = chunkMap[chunkName];
const size = ((chunkStats && (chunkStats.parsedSize || chunkStats.statSize)) || 0) / 1000;
const gzipSize = ((chunkStats && chunkStats.gzipSize) || 0) / 1000;

const chunkInfo = `${chunkName} ${chalk.yellow(`(${size}kB)`)}${
gzipSize ? `/ ${chalk.blue(`(${gzipSize}kB gz)`)}` : ''
}`;
const chunkInfo = `${chunkName} ${chalk.yellow(`(${size}kB)`)}${
gzipSize ? ` / ${chalk.blue(`(${gzipSize}kB gz)`)}` : ''
}`;

if (size > 250) {
const largestPackage = findLargestPackage(chunkStats);
if (largestPackage) {
return `${chunkInfo}\nLargest dependency is ${largestPackage.name} (${chalk.yellow(
`${largestPackage.size / 1000}kB`
)})`;
if (size > 250) {
const largestPackage = findLargestPackage(chunkStats);
if (largestPackage) {
return `${chunkInfo}\nLargest dependency is ${largestPackage.name} ${chalk.yellow(
`(${largestPackage.size / 1000}kB)`
)}`;
}
}
return chunkInfo;
}
return chunkInfo;
}
});
});

let errors = '';
let warnings = '';
Expand Down
Loading

0 comments on commit bd6cc17

Please sign in to comment.