UNPKG

770 BJavaScriptView Raw
1"use strict";
2
3/**
4 * Assets are the full emitted bundles.
5 */
6const filesize = require("filesize");
7
8function _getAssetSize(asset) {
9 return filesize(asset.size || 0);
10}
11
12function _getTotalSize(assetsList) {
13 return filesize(assetsList.reduce((total, asset) => total + (asset.size || 0), 0));
14}
15
16function _printAssets(assetsList) {
17 return [["Name", "Size"]]
18 .concat(assetsList.map(asset => [asset.name, _getAssetSize(asset)]))
19 .concat([["Total", _getTotalSize(assetsList)]]);
20}
21
22function formatAssets(assets) {
23 // Convert to list.
24 const assetsList = Object.keys(assets).map(name => ({
25 name,
26 size: assets[name].meta.full
27 }));
28
29 return _printAssets(assetsList);
30}
31
32module.exports = { formatAssets, _getAssetSize, _getTotalSize, _printAssets };