How do I view the size of npm packages?

后端 未结 10 1689
故里飘歌
故里飘歌 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:35

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

    • webpack-bundle-analyzer
    • webpack-bundle-size-analyzer

    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.

    0 讨论(0)
  • 2020-12-22 17:37

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

    Installation: npm install -g cost-of-modules

    Usage: Run cost-of-modules in the directory you are working in.

    0 讨论(0)
  • 2020-12-22 17:39

    Try to use package-size.

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

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

    0 讨论(0)
  • 2020-12-22 17:41

    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.com

    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


    Update 2020

    The "Unpacked Size" (basically Publish Size) is available on the npmjs.com website along with "Total Files". However, this is not recursive meaning that npm install will likely be much bigger because a single package likely depends on many packages (thus Package Phobia is still relevant).

    There is also a pending RFC for a feature which prints this information from the CLI.

    0 讨论(0)
提交回复
热议问题