项目作者: egoist

项目描述 :
Get the bundle size of an npm package.
高级语言: JavaScript
项目地址: git://github.com/egoist/package-size.git
创建时间: 2016-12-23T15:28:04Z
项目社区:https://github.com/egoist/package-size

开源协议:MIT License

下载



package-size



NPM version NPM downloads Build Status donate


preview

How does this work?

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

Install

  1. yarn global add package-size

Usage

The package is bundled with Webpack.

  1. # get the size of vue bundle
  2. package-size vue
  3. # get the size of react+react-dom bundle
  4. package-size react,react-dom
  5. # get the size of vue react+react-dom preact bundles
  6. package-size vue react,react-dom preact
  7. # get the size of react+react-dom without using the cache
  8. package-size react,react-dom --no-cache
  9. # get the size of file in current working directory
  10. package-size ./dist/index.js
  11. # or a package in current working directory, explictly using `--cwd` flag
  12. package-size vue --cwd
  13. # or event multiple versions for the same package!
  14. package-size react@0.10 react@0.14 react@15
  15. # save results to file system in JSON format
  16. # defaults to ./package-size-output.json
  17. package-size cherow --output
  18. # or custom path
  19. package-size cherow --output stats.json
  20. # analyze bundle with webpack-bundle-analyzer
  21. package-size cherow --analyze
  22. # analyze bundle with webpack-bundle-analyzer on a different port
  23. package-size cherow --analyze --port 9000

API

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

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. package-size styled-jsx/style --externals react

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

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. 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