How do I view the size of npm packages?

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

How can I determine how much NPM package will be added to my project?

+101


source to share


9 replies


What you probably want to measure is the impact of the package if you add it to your application package. Most of the other answers will only estimate the size of the source files, which may be inaccurate due to inline comments, long variable names, etc.

I made a little utility that will tell you the minimum + gzip size of a package after it gets into your package -



https://bundlephobia.com

+134


source


Take a look at this cost-of-modules project . This is an npm package that will list the package size and the number of children.

Installation: npm install -g cost-of-modules



Usage: Run cost-of-modules

in the directory you are working in.

enter image description here

+61


source


I created a tool, npm download size , that checks the tarball size for a given npm package, including all tarballs in the dependency tree.

download size of webpack

In the image above, the Tarball size is the tar.gz package and the Total size is the size of all tarballs. The tool is pretty basic, but it does what it says.

Cli tool is also available. You can install it like this:

npm i -g download-size

      

And use it like this:

$ download-size request
request@2.83.0: 1.08 MiB

      

Here is a demo of asciinema .

Source code is available on Github: API , Cli tool, and web client .

+20


source


I created Package Phobia earlier this year with the hopes of getting information about the package size on npmjs.com and also tracking package distribution times.

https://packagephobia.now.sh

img

It is designed to measure disk space after startup npm install

for server dependencies like express

or dev like jest

.

You can read more about this tool and other similar tools in the readme here: https://github.com/styfle/packagephobia


Note. Even though the npm team is not trying to change the website, they are considering adding a set size to the cli. See RFC 1 for more information.

+15


source


In case you are using webpack as your module module take a look at:

I would definitely recommend the first option. Shows the size in an interactive tree map. This will help you find the package size in your file.

Webpack Bundle Analyzer

The other answers in this post show you the size of the project, but you may not use all parts of the project, for example with tree shake. Then other approaches may not show you the exact size.

+11


source


Try using the package size .

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

      

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

+8


source


If you are using Visual Studio Code, you can use an extension called Import Cost .

This extension will display the size of the imported package inline in the editor. The extension uses webpack with the babili-webpack-plugin to determine the imported size.

+3


source


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

Using:

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

      

This may sound a little verbose, but it solves the problem you described appropriately.

+2


source


The "quick and dirty" way is to use curl and wzrd.in to quickly download the minified package and then grep the file size

curl -i https://wzrd.in/standalone/axios@latest | grep Content-Length

The download is a thumbnail but not gzipped, but you get an idea of โ€‹โ€‹the relative size of the packages when comparing two or more of them.

+2


source







All Articles