当我在NPM上搜索包时,我想看到包的大小(KB或MB等)。NPM似乎没有显示这一信息。

我如何确定一个NPM包会给我的项目增加多少膨胀?


当前回答

尽量使用包装大小。

npx package-size vue,vue-router,vuex react,react-dom,react-router,redux

https://github.com/egoist/package-size

其他回答

看看这个模块成本项目。这是一个npm包,它会列出包的大小和子元素的数量。

安装: NPM install -g cost-of-modules

用法: 在您工作的目录中运行cost-of-modules。

为了检查不同的包对你的包的影响。你可以查看source-map-explorer。

安装:

npm install -g source-map-explorer

用法:

source-map-explorer bundle.min.js
source-map-explorer bundle.min.js bundle.min.js.map
source-map-explorer bundle.min.js*
source-map-explorer *.js

这将打开一个可视化的空间是如何在您的压缩包中使用的。

在发布npm包之前,你可以使用下面的命令检查包的大小。

NPM发布——试运行

我已经附上了npm包的结果。

你可以查看npm-module-stats。它是一个npm模块,可以获取npm模块的大小及其依赖项,而无需安装或下载该模块。

用法:

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);
});

它可能看起来有点啰嗦,但它解决了您恰当描述的问题。

Howfat是另一个显示总包装大小的工具:

npx howfat jasmine