How do I view the size of npm packages?

2019-03-07 20:40发布

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 bloat an NPM package will add to my project?

标签: npm package size
9条回答
该账号已被封号
2楼-- · 2019-03-07 21:17

I created Package Phobia early this year with the hope to get the package size information into npmjs.com and also track package bloat over time.

https://packagephobia.now.sh

img

This is designed to measure disk space after you run npm install for server-side dependencies like express or dev dependencies like jest.

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


Note: Although there is no movement from the npm team to change the website, they are looking at adding the installed size to the cli. See RFC 1 for more info.

查看更多
孤傲高冷的网名
3楼-- · 2019-03-07 21:18

What you probably want to measure is the impact a package has if you were to add it to your app bundle. Most of the other answers will estimate the size of the source files only, which maybe inaccurate due to inline comments, long var names etc.

There is a small utility I made that'll tell you the min + gzipped size of the package after it gets into you bundle -

https://bundlephobia.com

查看更多
老娘就宠你
4楼-- · 2019-03-07 21:20

A "quick & 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 minified but not gzipped, but you get a good idea of the relative size of packages when you compare two or more of them.

查看更多
smile是对你的礼貌
5楼-- · 2019-03-07 21:26

If you use Visual Studio Code, you could use an extension called Import Cost.

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

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-03-07 21:27

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

I definitely recommend the first option. It shows size in interactive treemap. This helps you to find the size of package in your bundled file.

Webpack Bundle Analyzer

The other answers in this post show you size of the project, but you might not be using all parts of the project, for example with tree shaking. Other approaches then might not show you accurate size.

查看更多
地球回转人心会变
7楼-- · 2019-03-07 21:27

Try to use package-size.

yarn global add package-size

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

查看更多
登录 后发表回答