• Stars
    star
    4,464
  • Rank 9,575 (Top 0.2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Keep your bundle size in check



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?

Β 

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

More Repositories

1

cost-of-modules

Find out which of your dependencies are slowing you down 🐒
JavaScript
2,784
star
2

auto-install

Install dependencies as you code ⚑️
JavaScript
1,197
star
3

react-ui

Customisable components and primitives based on design tokens
JavaScript
417
star
4

notella

No fluff notes app
JavaScript
274
star
5

card-vibes

The card component with good vibes
JavaScript
262
star
6

babel-plugin-open-source

Alt + Click on rendered JSX to open it's source code in VSCode
JavaScript
184
star
7

github-build

Github builds for CI
JavaScript
131
star
8

react-amsterdam-videos

Timestamps from the react.asterdam livestream
127
star
9

women-tech-speakers-in-india

A list of women tech speakers in India
121
star
10

atom-import-cost

Check the size of the package you import
JavaScript
119
star
11

bae

react made easy
JavaScript
113
star
12

rest-your-eyes

Rest your eyes while your command runs πŸ‘€
JavaScript
106
star
13

css-constructor

πŸ’„ CSS constructor for React components
JavaScript
99
star
14

now-cd

continuous deployment with now
JavaScript
93
star
15

twitter-avatar

Get twitter avatar from a username
JavaScript
91
star
16

css-out-js

Author styles collocated in JS, pull them out into static CSS on build. No runtime dependency.
JavaScript
91
star
17

use-timeout

Declarative React hook for setTimeout
JavaScript
77
star
18

perfbench

Continuous integration for performance monitoring
JavaScript
74
star
19

tracer-motion

Visual debugger for framer-motion
JavaScript
69
star
20

reactron

β˜‰ A shiny new React component library
JavaScript
67
star
21

historie

A searchable history cli
JavaScript
59
star
22

show-keys

Utility to show key presses in your application
JavaScript
57
star
23

react-vanilla-tilt

React wrapper around vanilla-tilt
JavaScript
53
star
24

twitter-timer

A tiny timer for twitter
JavaScript
51
star
25

saturday

Example app for React Day talk
JavaScript
48
star
26

bundlesize2

Keep your bundle size in check - version 2
JavaScript
48
star
27

prettycli

Pretty print messages on the terminal
JavaScript
47
star
28

learn-es6

Learn ES6 while converting your ES5 code!
JavaScript
46
star
29

ci-env

Environment variables exposed by CI tools
JavaScript
40
star
30

npm-cache-benchmark

Benchmark npm cache vs yarn
JavaScript
38
star
31

pay-with-a-star

Get paid in ⭐s for your open source work
JavaScript
34
star
32

react-docgen-external-proptypes-handler

evaluate variables from external files for react-docgen
JavaScript
34
star
33

toggle-icons

show/hide icons on your desktop
JavaScript
30
star
34

use-css

Silly React hook for CSS
JavaScript
25
star
35

storehook

silly state management library built with hooks
JavaScript
24
star
36

jsxo

Babel plugin that lets you create files with JSX only
JavaScript
22
star
37

useDebug

Custom hook to debug useEffect
JavaScript
21
star
38

just-do-it-pls

a collaborative "art" project
HTML
18
star
39

react-rally-videos

Timestamps from the react.asterdam livestream
18
star
40

use-event-listener

Declarative React hook for eventListener
JavaScript
16
star
41

tinyreact.email

Top 3 React articles of the week in your inbox
HTML
16
star
42

nps-i

Interactive mode for nps
JavaScript
16
star
43

robocop

Robocop is a code review tool
JavaScript
15
star
44

tweetshot

Quicky grab a screenshot of a tweet
JavaScript
15
star
45

markedup

WIP: Supercharged markdown rendering engine
JavaScript
14
star
46

babel-plugin-styled-components-require

Babel plugin that adds styled-components import declaration
JavaScript
13
star
47

travis.yml

Quickly create a .travis.yml for node projects
JavaScript
13
star
48

twitter-stats

Get followers for a user
JavaScript
11
star
49

atom-import-cost-beta

JavaScript
10
star
50

ynx

just like npx but bΜΆeΜΆtΜΆtΜΆeΜΆrΜΆ same
JavaScript
8
star
51

fakestagram

react web and native from the same codebase
JavaScript
8
star
52

ci-github-comment

Comment on pull requests from CI
JavaScript
8
star
53

vscode-settings

Copy of my editor setup
7
star
54

is-public

Check if a github repo is public
JavaScript
7
star
55

unique-string-pokemon

Get a unique hyphenated string like pikachu-used-thunder-shock
JavaScript
7
star
56

rehman

JavaScript
7
star
57

restylesheet

Best way to include stylesheet for developer-kids these days
JavaScript
7
star
58

use-key-debugger

React hook for visually debugging keyboard events
JavaScript
6
star
59

regithub

Playground to perform my React experiments
JavaScript
6
star
60

lazyfetch

Load stuff lazily on the browser
JavaScript
5
star
61

react-workshop

Companion repo
JavaScript
5
star
62

react-newsletter

Tools for react newsletter
JavaScript
5
star
63

react-ui-devtools-example

JavaScript
5
star
64

shelf-examples

Examples for using shelf
HTML
5
star
65

react-docgen-deprecation-handler

Add deprecation status in prop types
JavaScript
5
star
66

vanilla-extract-prototype

Built a couple components with vanilla extract
CSS
4
star
67

react-prototype

Designing with react, because why not?
JavaScript
4
star
68

prettyreadme

Automated my style of readme
JavaScript
4
star
69

gradients-api

Get colors for gradient name
JavaScript
4
star
70

advanced-react

JavaScript
3
star
71

ds-workshop

JavaScript
3
star
72

prettytext

I like gradients
JavaScript
3
star
73

ra-workshop

JavaScript
3
star
74

supervisorduty

Checks supervisor status and raises a pager duty alert
JavaScript
3
star
75

es6-on-production

ES6 on production? Not so fast
JavaScript
3
star
76

beep

nodeschool workshop
JavaScript
3
star
77

vhs

πŸ“Ό
JavaScript
3
star
78

dribbble

A design system for Dribbble
CSS
3
star
79

now-wrapper

A programmatic API around now CLI
JavaScript
3
star
80

dhai-kilo-ka-haath

dhai kilo ka file πŸ’ͺ
2
star
81

github-user

Get bio + popular repos for a user
JavaScript
2
star
82

sandbox

WIP: Sandbox 5
JavaScript
2
star
83

props-to-string

Human readable names for proptypes
2
star
84

dribbble-backup

JavaScript
2
star
85

heels

JavaScript
2
star
86

codesee-example

JavaScript
2
star
87

vite-example

Vue
2
star
88

calendar-tasks

Add BETTER tasks to google calendar
JavaScript
2
star
89

lighthouse-ci

Trying to run lighthouse on travis-ci
JavaScript
2
star
90

rpm

experiment: download node_modules via a remote server with faster internet
JavaScript
1
star
91

newstyle

CSS
1
star
92

github-comment

Comment on a pull request
JavaScript
1
star
93

siddharthkp

Personal readme <3
1
star
94

whereami

JavaScript
1
star
95

dragonberry

Hackathon project with raspberry pi
JavaScript
1
star
96

advanced-component-patterns

Repo for advanced component patterns course
JavaScript
1
star
97

cdn-benchmarks

Benchmarking certain CDNs
JavaScript
1
star
98

twitter-uid-to-username

Get username for uid
JavaScript
1
star
99

robin

Application health at a glance
JavaScript
1
star
100

cronduty-cli

WIP: cron monitoring with minimal configuration πŸ“Ÿ
JavaScript
1
star