Skip to content

Commit

Permalink
Merged in bundle-analyzer-json (pull request #36)
Browse files Browse the repository at this point in the history
Write stats json file in BundleAnalyzerReporter

Approved-by: Will Binns-Smith
  • Loading branch information
padmaia committed Apr 14, 2020
2 parents afca002 + d8db7db commit 1f33b21
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/reporters/bundle-analyzer/src/BundleAnalyzerReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default new Reporter({

await Promise.all(
[...bundlesByTarget.entries()].map(async ([targetName, bundles]) => {
return options.outputFS.writeFile(
await options.outputFS.writeFile(
path.join(reportsDir, `${targetName}-stats.json`),
JSON.stringify(getBundleStats(bundles), null, 2),
);
await options.outputFS.writeFile(
path.join(reportsDir, `${targetName}.html`),
`
<html>
Expand Down Expand Up @@ -106,6 +110,15 @@ function getBundleData(
};
}

function getBundleStats(bundles: Array<Bundle>) {
return {
assets: bundles.map(({displayName, stats: {size}}) => ({
name: displayName,
size,
})),
};
}

type File = {|
basename: string,
stats: Stats,
Expand Down

0 comments on commit 1f33b21

Please sign in to comment.