How do I view the size of npm packages?

后端 未结 10 1687
故里飘歌
故里飘歌 2020-12-22 16:53

When I search for packages on NPM, I would like to see package sizes (in KB or MB, etc). NPM doesn’t seem to show this information.

How can I determine how much bloa

10条回答
  •  生来不讨喜
    2020-12-22 17:18

    You could check out npm-module-stats. It is an npm module that gets the size of an npm module and its dependencies without installing or downloading the module.

    Usage:

    var stats = require("npm-module-stats");
    
    stats.getStats("glob").then((stack) => {
    
      let dependencies = Object.keys(stack);
      let totalSize = dependencies.reduce((result, key, index) => {
        return result + stack[key].size;
      }, 0);
    
      console.log('Total Size in Bytes ', totalSize);
      console.log('Total Dependencies ', dependencies.length-1);
    
    }).catch((err) => {
      console.error(err);
    });
    

    It might seem a little verbose but it solves the problem you described appropriately.

提交回复
热议问题