GithubHelp home page GithubHelp logo

michaeldeboey / bundlesize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from siddharthkp/bundlesize

1.0 2.0 0.0 2 MB

Keep your bundle size in check

License: MIT License

JavaScript 83.56% CSS 5.42% Pug 11.02%

bundlesize's Introduction



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

    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 5 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}
  • CI=true usually set automatically in CI environments

(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?

⭐ this repo

 

How to contribute?

 

 

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

bundlesize's People

Contributors

0xflotus avatar alejandronanez avatar andarist avatar asood123 avatar bogas04 avatar callumlocke avatar cclauss avatar cg-cnu avatar christineoo avatar cristianossd avatar daniel15 avatar danyshaanan avatar edmorley avatar fdnhkj avatar fezvrasta avatar forsakenharmony avatar furizaa avatar greenkeeper[bot] avatar haroenv avatar kakadiadarpan avatar karanjthakkar avatar kuldeepkeshwar avatar michaltk avatar montmanu avatar palashmon avatar penx avatar quantizor avatar reznord avatar saravieira avatar siddharthkp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.