diff --git a/src/analyzer.js b/src/analyzer.js index 40372749..c58d5e93 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -20,7 +20,8 @@ module.exports = { function getViewerData(bundleStats, bundleDir, opts) { const { logger = new Logger(), - excludeAssets = null + excludeAssets = null, + compressedSize = gzipSize } = opts || {}; const isAssetIncluded = createAssetsFilter(excludeAssets); @@ -102,7 +103,7 @@ function getViewerData(bundleStats, bundleDir, opts) { if (assetSources) { asset.parsedSize = Buffer.byteLength(assetSources.src); - asset.gzipSize = gzipSize(assetSources.src); + asset.gzipSize = compressedSize(assetSources.src); } // Picking modules from current bundle script @@ -143,7 +144,7 @@ function getViewerData(bundleStats, bundleDir, opts) { } asset.modules = assetModules; - asset.tree = createModulesTree(asset.modules); + asset.tree = createModulesTree(asset.modules, {compressedSize}); return result; }, {}); @@ -203,8 +204,8 @@ function isRuntimeModule(statModule) { return statModule.moduleType === 'runtime'; } -function createModulesTree(modules) { - const root = new Folder('.'); +function createModulesTree(modules, opts) { + const root = new Folder('.', opts); modules.forEach(module => root.addModule(module)); root.mergeNestedFolders(); diff --git a/src/tree/Folder.js b/src/tree/Folder.js index fb121be6..15748227 100644 --- a/src/tree/Folder.js +++ b/src/tree/Folder.js @@ -1,5 +1,4 @@ import _ from 'lodash'; -import {gzipSize} from '../sizeUtils'; import Module from './Module'; import BaseFolder from './BaseFolder'; @@ -8,13 +7,18 @@ import {getModulePathParts} from './utils'; export default class Folder extends BaseFolder { + constructor(name, opts) { + super(name); + this.opts = opts; + } + get parsedSize() { return this.src ? this.src.length : 0; } get gzipSize() { if (!_.has(this, '_gzipSize')) { - this._gzipSize = this.src ? gzipSize(this.src) : 0; + this._gzipSize = this.src ? this.opts.compressedSize(this.src) : 0; } return this._gzipSize; @@ -42,7 +46,7 @@ export default class Folder extends BaseFolder { // See `test/stats/with-invalid-dynamic-require.json` as an example. !(childNode instanceof Folder) ) { - childNode = currentFolder.addChildFolder(new Folder(folderName)); + childNode = currentFolder.addChildFolder(new Folder(folderName, this.opts)); } currentFolder = childNode;