bundlesize
Keep your library size in check
Last updated 2 years ago by saravieira .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install bundlesize 
SYNC missed versions from official npm registry.



Keep your bundle size in check

 

Build Status NPM Version NPM Downloads  

Setup

npm install bundlesize --save-dev

# or

yarn add bundlesize --dev

 

Usage

 

Add it to your scripts in package.json

"scripts": {
  "test": "bundlesize"
}

Or you can use it with npx from NPM 5.2+.

npx bundlesize

 

Configuration

 

bundlesize accepts an array of files to check.

[
  {
    "path": "./build/vendor.js",
    "maxSize": "30 kB"
  },
  {
    "path": "./build/chunk-*.js",
    "maxSize": "10 kB"
  }
]

 

You can keep this array either in

  1. package.json

    {
      "name": "your cool library",
      "version": "1.1.2",
      "bundlesize": [
        {
          "path": "./build/vendor.js",
          "maxSize": "3 kB"
        }
      ]
    }
    

    or in a separate file

  2. bundlesize.config.js

    Format:

    {
      "files": [
        {
          "path": "./dist.js",
          "maxSize": "3 kB"
        }
      ]
    }
    

    You can give a different file by using the --config flag:

    bundlesize --config configs/bundlesize.json
    

 

Customisation

 

  1. Fuzzy matching

    If the names of your build files are not predictable, you can use the glob pattern to specify files.

    This is common if you append a hash to the name or use a tool like create-react-app/nextjs.

    {
      "files": [
        {
          "path": "build/**/main-*.js",
          "maxSize": "5 kB"
        },
        {
          "path": "build/**/*.chunk.js",
          "maxSize": "50 kB"
        }
      ]
    }
    

    It will match multiple files if necessary and create a new row for each file.

     

  2. Compression options

    By default, bundlesize gzips your build files before comparing.

    If you are using brotli instead of gzip, you can specify that with each file:

    {
      "files": [
        {
          "path": "./build/vendor.js",
          "maxSize": "5 kB",
          "compression": "brotli"
        }
      ]
    }
    

    If you do not use any compression before sending your files to the client, you can switch compression off:

    {
      "files": [
        {
          "path": "./build/vendor.js",
          "maxSize": "5 kB",
          "compression": "none"
        }
      ]
    }
    

 

Build status for GitHub

 

If your repository is hosted on GitHub, you can set bundlesize up to create a "check" on every pull request.

build status

Currently works with Travis CI, CircleCI, Wercker, and Drone.

Using a different CI? You will need to supply an additional 4 environment variables.

  • CI_REPO_OWNER given the repo https://github.com/myusername/myrepo would be myusername
  • CI_REPO_NAME given the repo https://github.com/myusername/myrepo would be myrepo
  • CI_COMMIT_MESSAGE the commit message
  • CI_COMMIT_SHA the SHA of the CI commit, in Jenkins you would use ${env.GIT_COMMIT}

(Ask me for help if you're stuck)

 

Usage with CLI

 

bundlesize can also be used without creating a configuration file. We do not recommend this approach and it might be deprecated in a future version.

bundlesize -f "dist/*.js" -s 20kB

For more granular configuration, we recommend configuring it in the package.json (documented above).

 

like it?

:star: this repo

 

how to contribute?

 

Featured on Totally tooling tips and Chrome Dev Summit!!

 

who uses bundlesize?

 

TODO

  • Work with other CI tools
  • Automate setup (setting env_var)

 

similar projects

Contributors

This project exists thanks to all the people who contribute. [Contribute].

license

MIT © siddharthkp

Current Tags

  • 1.0.0-beta.2                                ...           beta (5 months ago)
  • 0.18.0                                ...           latest (5 months ago)

49 Versions

  • 1.0.0-beta.2                                ...           5 months ago
  • 1.0.0-beta.1                                ...           5 months ago
  • 0.18.0                                ...           5 months ago
  • 0.17.2                                ...           7 months ago
  • 0.17.1                                ...           a year ago
  • 0.17.0                                ...           2 years ago
  • 0.16.0                                ...           2 years ago
  • 0.15.3                                ...           2 years ago
  • 0.15.2                                ...           2 years ago
  • 0.15.1                                ...           2 years ago
  • 0.15.0                                ...           2 years ago
  • 0.14.4                                ...           2 years ago
  • 0.14.3                                ...           2 years ago
  • 0.14.2                                ...           2 years ago
  • 0.14.1                                ...           2 years ago
  • 0.14.0                                ...           2 years ago
  • 0.13.2                                ...           2 years ago
  • 0.13.1                                ...           2 years ago
  • 0.13.0                                ...           2 years ago
  • 0.12.2                                ...           2 years ago
  • 0.12.1                                ...           2 years ago
  • 0.12.0                                ...           2 years ago
  • 0.11.2                                ...           2 years ago
  • 0.11.1                                ...           2 years ago
  • 0.11.0                                ...           2 years ago
  • 0.10.0                                ...           2 years ago
  • 0.9.2                                ...           2 years ago
  • 0.9.1                                ...           2 years ago
  • 0.9.0                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.1                                ...           2 years ago
  • 0.7.0                                ...           2 years ago
  • 0.6.1                                ...           2 years ago
  • 0.6.0                                ...           2 years ago
  • 0.5.9                                ...           2 years ago
  • 0.5.8                                ...           2 years ago
  • 0.5.7                                ...           2 years ago
  • 0.5.6                                ...           2 years ago
  • 0.5.5                                ...           2 years ago
  • 0.5.4                                ...           2 years ago
  • 0.5.3                                ...           2 years ago
  • 0.5.2                                ...           2 years ago
  • 0.5.1                                ...           2 years ago
  • 0.5.0                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Downloads
Today 102
This Week 333
This Month 691
Last Day 121
Last Week 343
Last Month 1,449
Dependencies (10)
Dev Dependencies (22)

Copyright 2014 - 2016 © taobao.org |