webpack-stats-diff
Advanced tools
Comparing version 0.5.0 to 0.6.0
{ | ||
"name": "webpack-stats-diff", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "CLI tool to report changes in bundle sizes across builds", | ||
@@ -5,0 +5,0 @@ "bin": "src/cli.js", |
# webpack-stats-diff | ||
CLI tool to report changes in bundle sizes across builds | ||
A command-line tool to report changes in bundle sizes across builds. | ||
## The problem | ||
You just made changes to your webpack config or your source files and you want to know how bundle sizes were impacted. | ||
## The solution | ||
Use this tool to see how much the total built file size has changed and see the breakdown for what files were added or removed as well as what files increased or decreased in size. | ||
## Installation & Usage | ||
Install with `npm install -g webpack-stats-diff` | ||
To compare your bundle sizes before and after, you'll need to configure webpack to save a stats file. This can be done by either adding a script to your package.json similar to `build_stats: webpack mode=production --json > stats.json` or by adding [webpack-stats-plugin](https://github.com/FormidableLabs/webpack-stats-plugin) into your plugins list. | ||
For example, to compare the bundle sizes between branches, you could save the master build stats to a file `master.json` and the branch build stats to `my-branch.json` and run | ||
``` | ||
webpack-stats-diff master.json my-branch.json | ||
``` | ||
![terminal showing the result of running the command](demo-screenshot.png) | ||
## Other Solutions | ||
* [webpack-compare](https://github.com/Southpaw17/webpack-compare) instead generates an HTML file to display the comparison, but it doesn't include totals or filtering options. |
@@ -55,2 +55,4 @@ #!/usr/bin/env node | ||
const capitalize = text => text[0].toUpperCase() + text.slice(1); | ||
const printAssetsTables = results => { | ||
@@ -60,18 +62,26 @@ ['added', 'removed', 'bigger', 'smaller'].forEach(field => { | ||
if (assets.length > 0) { | ||
const sectionStyling = ['added', 'bigger'].includes(field) | ||
? chalk.green.bold | ||
: chalk.red.bold; | ||
console.log(sectionStyling(field)); | ||
const sectionColor = ['added', 'bigger'].includes(field) | ||
? chalk.green.underline.bold | ||
: chalk.red.underline.bold; | ||
console.log(sectionColor(capitalize(field))); | ||
const tableData = [ | ||
TABLE_HEADERS, | ||
...assets.map(asset => [ | ||
asset.name, | ||
getSizeText(asset.oldSize), | ||
getSizeText(asset.newSize), | ||
getSizeText(asset.diff), | ||
`${asset.diffPercentage} %` | ||
]) | ||
]; | ||
console.log(table(tableData, ASSET_TABLE_CONFIG)); | ||
if (['added', 'removed'].includes(field)) { | ||
const tableData = [ | ||
[chalk.bold('Asset'), chalk.bold('Diff')], | ||
...assets.map(asset => [asset.name, getSizeText(asset.diff)]) | ||
]; | ||
console.log(table(tableData, ASSET_TABLE_CONFIG)); | ||
} else { | ||
const tableData = [ | ||
TABLE_HEADERS, | ||
...assets.map(asset => [ | ||
asset.name, | ||
getSizeText(asset.oldSize), | ||
getSizeText(asset.newSize), | ||
getSizeText(asset.diff), | ||
`${asset.diffPercentage} %` | ||
]) | ||
]; | ||
console.log(table(tableData, ASSET_TABLE_CONFIG)); | ||
} | ||
} | ||
@@ -78,0 +88,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
251065
12
387
30