stats.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const ModulesUtils = require('./modules')
  2. const sizeTypes = ['stats', 'parsed', 'gzip']
  3. exports.processStats = function (stats) {
  4. const rawModules = ModulesUtils.filterModules(stats.data.modules)
  5. const modulesPerSizeType = {}
  6. const analyzer = {}
  7. for (const sizeType of sizeTypes) {
  8. const modules = ModulesUtils.buildSortedModules(rawModules, sizeType)
  9. const modulesTotalSize = modules.reduce((total, module) => total + module.size, 0)
  10. const depModules = ModulesUtils.buildDepModules(modules)
  11. const depModulesTotalSize = depModules.reduce((total, module) => total + module.size, 0)
  12. modulesPerSizeType[sizeType] = {
  13. modulesTotalSize,
  14. depModules,
  15. depModulesTotalSize
  16. }
  17. const modulesTrees = ModulesUtils.buildModulesTrees(rawModules, sizeType)
  18. analyzer[sizeType] = {
  19. modulesTrees
  20. }
  21. }
  22. stats = {
  23. data: {
  24. errors: stats.data.errors,
  25. warnings: stats.data.warnings,
  26. assets: stats.data.assets.map(a => ({
  27. name: a.name,
  28. size: a.size
  29. })),
  30. chunks: stats.data.chunks.map(c => ({
  31. id: c.id,
  32. names: c.names
  33. }))
  34. },
  35. computed: {
  36. modulesPerSizeType
  37. }
  38. }
  39. return {
  40. stats,
  41. analyzer
  42. }
  43. }