webpack-build-report
Advanced tools
Comparing version 1.0.1 to 1.1.0
55
index.js
"use strict" | ||
const fs = require('fs'); | ||
const colors = require('colors') | ||
const assetsUtils = require('./utils/assets') | ||
const cliUtils = require('./utils/cli') | ||
const coreUtils = require('./utils/core') | ||
const reportUtils = require('./utils/report') | ||
const statsUtils = require('./utils/stats') | ||
@@ -10,4 +13,6 @@ module.exports = class BuildReportPlugin { | ||
this.options = Object.assign({}, { | ||
append: false, | ||
assets: true, | ||
output: 'build-report.md', | ||
assets: true | ||
saveStats: true | ||
}, options) | ||
@@ -19,2 +24,4 @@ } | ||
cliUtils.log('start') | ||
// Convert stats to something more readable | ||
@@ -26,35 +33,23 @@ stats = stats.toJson(); | ||
// Report generic info | ||
report += reportUtils.buildGenericInfo(stats) | ||
// Report assets | ||
if (this.options.assets) { | ||
report += this.buildAssetsList(stats.assets) | ||
report += assetsUtils.buildAssetsList(stats.assets) | ||
} | ||
// Output the report | ||
fs.writeFile(this.options.output, report, err => { | ||
if (err) { | ||
return console.log(' BUILD REPORT '.inverse.red, err) | ||
// Save the report | ||
reportUtils.save( | ||
report, | ||
this.options.append ? 'append' : 'write', | ||
this.options.output, | ||
_ => { | ||
if (this.options.saveStats) { | ||
statsUtils.save(stats) | ||
} | ||
} | ||
console.log( | ||
'\n\n', | ||
' BUILD REPORT '.inverse.green, | ||
'💾 ', | ||
'File', | ||
`${this.options.output}`.yellow.bold, | ||
'successfully saved !', | ||
'\n\n' | ||
) | ||
}) | ||
) | ||
}) | ||
} | ||
buildAssetsList (assets) { | ||
let assetsList = '### Assets list\n' | ||
assetsList += 'Asset name | Asset size\n--- | ---\n' | ||
assets.forEach(asset => { | ||
assetsList += `${asset.name} | ${(asset.size / 1000).toFixed(2)} kB\n` | ||
}) | ||
return assetsList | ||
} | ||
} |
{ | ||
"name": "webpack-build-report", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Build a report file after a Webpack build", | ||
@@ -26,4 +26,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"colors": "^1.1.2" | ||
"colors": "^1.1.2", | ||
"moment": "^2.17.1" | ||
} | ||
} |
@@ -30,3 +30,4 @@ # webpack-build-report | ||
assets: true, | ||
output: `${SRC_DIR}/doc/build-report.md` | ||
output: `${SRC_DIR}/doc/build-report.md`, | ||
... | ||
}) | ||
@@ -44,4 +45,6 @@ ] | ||
---| --- | --- | --- | ||
append | bool | false | Appends the report to an existing `.md` file, based on the `output` option | ||
assets | bool | true | Adds the assets stats to the final report | ||
output | string | 'build-report.md' | Tell the plugin where you want your report to be saved. Must be an `.md` file ! | ||
saveStats | bool | false | Saves the complete build stats in `.build-stats.json`, and allow your report to show comparisons to the last build | ||
@@ -52,10 +55,16 @@ --- | ||
# Build report | ||
- Hash: **3776828640c3fab88ac5** | ||
- Version: webpack **1.14.0** | ||
- Time: **2813**ms | ||
- Generated on : **December 17, 2016 4:48 PM** | ||
### Assets list | ||
Asset name | Asset size | ||
--- | --- | ||
AlertIllustration.js | 17.41 kB | ||
Button.js | 8.41 kB | ||
Checkbox.js | 7.26 kB | ||
Loader.js | 6.07 kB | ||
Modal.js | 15.93 kB | ||
PhoneLoader.js | 16.66 kB | ||
Asset name | Asset size | Size difference | ||
--- | --- | --- | ||
AlertIllustration.js | 17.41 kB | +6.45 kB | ||
Button.js | 8.41 kB | - | ||
Checkbox.js | 7.26 kB | - | ||
Loader.js | 6.07 kB | -21.12 kB | ||
Modal.js | 15.93 kB | - | ||
PhoneLoader.js | 16.66 kB | -4.00 kB |
7137
9
169
68
2
2
+ Addedmoment@^2.17.1
+ Addedmoment@2.30.1(transitive)