npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

package-size

v2.3.0

Published

Get real size of an npm package after bundled.

Downloads

207

Readme

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

yarn global add package-size

Usage

The package is bundled with Webpack.

# get the size of vue bundle
package-size vue

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

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

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

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

# or event multiple versions for the same package!
package-size [email protected] [email protected] react@15

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

# analyze bundle with webpack-bundle-analyzer
package-size cherow --analyze
# analyze bundle with webpack-bundle-analyzer on a different port
package-size cherow --analyze --port 9000

API

const getSizes = require('package-size')

getSizes('react,react-dom', options)
  .then(data => {
    console.log(data)
    //=>
    {
      name: 'react,react-dom',
      size: 12023, // in bytes
      minified: 2342,
      gzipped: 534,
      versionedName: '[email protected],[email protected]'
    }
  })

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:

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