UNPKG

bonsai-analyzer

Version:
34 lines (31 loc) 723 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getModulesByChunk; function getModulesByChunk(stats, chunkWhitelist) { const map = {}; stats.chunks.forEach(chunk => { if (chunkWhitelist.includes(chunk.id)) { map[chunk.id] = { id: chunk.id, length: 0, modules: [] }; } }); stats.modules.forEach(module => { module.chunks.forEach(chunk => { if (map[chunk]) { map[chunk].modules = map[chunk].modules.concat(module); } }); }); Object.keys(map).forEach(key => { map[key].length = map[key].modules.length; if (map[key].length === 0) { delete map[key]; } }); return map; }