npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

package-size


preview

How does this work?


Install the packages with yarn or npm in a temp directory
Bundle the packages with webpack and get the bundle size
Show you the bundle size and cache it by package version

Install


  1. ``` shell
  2. yarn global add package-size
  3. ```

Usage


The package is bundled with Webpack.

  1. ``` shell
  2. # get the size of vue bundle
  3. package-size vue

  4. # get the size of react+react-dom bundle
  5. package-size react,react-dom

  6. # get the size of vue react+react-dom preact bundles
  7. package-size vue react,react-dom preact

  8. # get the size of react+react-dom without using the cache
  9. package-size react,react-dom --no-cache

  10. # get the size of file in current working directory
  11. package-size ./dist/index.js
  12. # or a package in current working directory, explictly using `--cwd` flag
  13. package-size vue --cwd

  14. # or event multiple versions for the same package!
  15. package-size react@0.10 react@0.14 react@15

  16. # save results to file system in JSON format
  17. # defaults to ./package-size-output.json
  18. package-size cherow --output
  19. # or custom path
  20. package-size cherow --output stats.json

  21. # analyze bundle with webpack-bundle-analyzer
  22. package-size cherow --analyze
  23. # analyze bundle with webpack-bundle-analyzer on a different port
  24. package-size cherow --analyze --port 9000
  25. ```

API


  1. ``` js
  2. const getSizes = require('package-size')

  3. getSizes('react,react-dom', options)
  4.   .then(data => {
  5.     console.log(data)
  6.     //=>
  7.     {
  8.       name: 'react,react-dom',
  9.       size: 12023, // in bytes
  10.       minified: 2342,
  11.       gzipped: 534,
  12.       versionedName: 'react@16.0.0,react-dom@16.0.0'
  13.     }
  14.   })
  15. ```

options


sort


Type: boolean Default: false

Sort packages in size (from small to large).

cwd


Type: boolean Default: false

Resolve modules in current working directory instead of a cache folder. Relative path will set cwd to true by default.

externals


Type: string or Array<string|RegExp> Default: undefined

The package to exclude from bundled file, for example, to get the bundle size of styled-jsx/style we need to exclude react :

  1. ``` shell
  2. package-size styled-jsx/style --externals react
  3. ```

Note that if some item in externals is provided as string, it will be wrapped in a regular expression. For example: react is treated as /^react$/

cache


Type: boolean Default: true

If cache is set to false, then package-size will not use cached build sizes. To use this from the CLI, pass --no-cache as an argument.

target


Type: string Default: browser Values: browser node

Build target. In node target, all node_modules will be excluded and output format is set to CommonJS.

registry


Type: string Default: undefined

npm registry to install the package from. By default it uses the default npm registry.

resolve


Type: string string[] Default: undefined

Extra folders to resolve local node_modules from.

Contributing


Fork it!
Create your feature branch: git checkout -b my-new-feature
Commit your changes: git commit -am 'Add some feature'
Push to the branch: git push origin my-new-feature
Submit a pull request :D

Author


package-size© EGOIST, Released under the MIT License.Authored and maintained by EGOIST with help from contributors (list ).

egoist.moe · GitHub @egoist · Twitter @_egoistlily

Last Updated: 2023-05-15 10:22:02