1 | <p align="center">
|
2 | <img src="https://cdn.rawgit.com/siddharthkp/bundlesize/master/art/logo.png" height="200px">
|
3 | <br><br>
|
4 | <b>Keep your bundle size in check</b>
|
5 | <br>
|
6 | </p>
|
7 |
|
8 |
|
9 |
|
10 | [![Build Status](https://travis-ci.org/siddharthkp/bundlesize.svg?branch=master)](https://travis-ci.org/siddharthkp/bundlesize)
|
11 | [![NPM Version](https://img.shields.io/npm/v/bundlesize.svg)](https://npmjs.org/package/bundlesize)
|
12 | [![NPM Downloads](https://img.shields.io/npm/dm/bundlesize.svg?style=flat)](https://www.npmjs.com/package/bundlesize)
|
13 |
|
14 |
|
15 | #### Setup
|
16 |
|
17 | ```sh
|
18 | npm install bundlesize --save-dev
|
19 |
|
20 | # or
|
21 |
|
22 | yarn add bundlesize --dev
|
23 | ```
|
24 |
|
25 |
|
26 |
|
27 | #### Usage
|
28 |
|
29 |
|
30 |
|
31 | Add it to your scripts in `package.json`
|
32 |
|
33 | ```json
|
34 | "scripts": {
|
35 | "test": "bundlesize"
|
36 | }
|
37 | ```
|
38 |
|
39 | Or you can use it with `npx` from [NPM 5.2+](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b).
|
40 |
|
41 | ```sh
|
42 | npx bundlesize
|
43 | ```
|
44 |
|
45 |
|
46 |
|
47 | #### Configuration
|
48 |
|
49 |
|
50 |
|
51 | `bundlesize` accepts an array of files to check.
|
52 |
|
53 | ```json
|
54 | [
|
55 | {
|
56 | "path": "./build/vendor.js",
|
57 | "maxSize": "30 kB"
|
58 | },
|
59 | {
|
60 | "path": "./build/chunk-*.js",
|
61 | "maxSize": "10 kB"
|
62 | }
|
63 | ]
|
64 | ```
|
65 |
|
66 |
|
67 |
|
68 | You can keep this array either in
|
69 |
|
70 | 1. `package.json`
|
71 |
|
72 | ```json
|
73 | {
|
74 | "name": "your cool library",
|
75 | "version": "1.1.2",
|
76 | "bundlesize": [
|
77 | {
|
78 | "path": "./build/vendor.js",
|
79 | "maxSize": "3 kB"
|
80 | }
|
81 | ]
|
82 | }
|
83 | ```
|
84 |
|
85 | or in a separate file
|
86 |
|
87 | 2. `bundlesize.config.json`
|
88 |
|
89 | Format:
|
90 |
|
91 | ```json
|
92 | {
|
93 | "files": [
|
94 | {
|
95 | "path": "./dist.js",
|
96 | "maxSize": "3 kB"
|
97 | }
|
98 | ]
|
99 | }
|
100 | ```
|
101 |
|
102 | You can give a different file by using the `--config` flag:
|
103 |
|
104 | ```
|
105 | bundlesize --config configs/bundlesize.json
|
106 | ```
|
107 |
|
108 |
|
109 |
|
110 | #### Customisation
|
111 |
|
112 |
|
113 |
|
114 | 1. Fuzzy matching
|
115 |
|
116 | If the names of your build files are not predictable, you can use the [glob pattern](https://github.com/isaacs/node-glob) to specify files.
|
117 |
|
118 | This is common if you append a hash to the name or use a tool like create-react-app/nextjs.
|
119 |
|
120 | ```json
|
121 | {
|
122 | "files": [
|
123 | {
|
124 | "path": "build/**/main-*.js",
|
125 | "maxSize": "5 kB"
|
126 | },
|
127 | {
|
128 | "path": "build/**/*.chunk.js",
|
129 | "maxSize": "50 kB"
|
130 | }
|
131 | ]
|
132 | }
|
133 | ```
|
134 |
|
135 | It will match multiple files if necessary and create a new row for each file.
|
136 |
|
137 |
|
138 |
|
139 | 2. Compression options
|
140 |
|
141 | By default, bundlesize `gzips` your build files before comparing.
|
142 |
|
143 | If you are using `brotli` instead of gzip, you can specify that with each file:
|
144 |
|
145 | ```json
|
146 | {
|
147 | "files": [
|
148 | {
|
149 | "path": "./build/vendor.js",
|
150 | "maxSize": "5 kB",
|
151 | "compression": "brotli"
|
152 | }
|
153 | ]
|
154 | }
|
155 | ```
|
156 |
|
157 | If you do not use any compression before sending your files to the client, you can switch compression off:
|
158 |
|
159 | ```json
|
160 | {
|
161 | "files": [
|
162 | {
|
163 | "path": "./build/vendor.js",
|
164 | "maxSize": "5 kB",
|
165 | "compression": "none"
|
166 | }
|
167 | ]
|
168 | }
|
169 | ```
|
170 |
|
171 |
|
172 |
|
173 | #### Build status for GitHub
|
174 |
|
175 |
|
176 |
|
177 | If your repository is hosted on GitHub, you can set bundlesize up to create a "check" on every pull request.
|
178 |
|
179 | ![build status](https://cdn.rawgit.com/siddharthkp/bundlesize/master/art/status.png)
|
180 |
|
181 | Currently works with [Travis CI](https://travis-ci.org), [CircleCI](https://circleci.com/), [Wercker](http://www.wercker.com), and [Drone](http://readme.drone.io/).
|
182 |
|
183 | - [Authorize `bundlesize` for status access](https://github.com/login/oauth/authorize?scope=repo%3Astatus&client_id=6756cb03a8d6528aca5a), copy the token provided.
|
184 | - Add this token as `BUNDLESIZE_GITHUB_TOKEN` as environment parameter in your CIs project settings.
|
185 |
|
186 | #### Using a different CI?
|
187 |
|
188 | You will need to supply an additional 5 environment variables.
|
189 |
|
190 | - `CI_REPO_OWNER` given the repo `https://github.com/myusername/myrepo` would be `myusername`
|
191 | - `CI_REPO_NAME` given the repo `https://github.com/myusername/myrepo` would be `myrepo`
|
192 | - `CI_COMMIT_MESSAGE` the commit message
|
193 | - `CI_COMMIT_SHA` the SHA of the CI commit, in [Jenkins](https://jenkins.io/) you would use `${env.GIT_COMMIT}`
|
194 | - `CI=true` usually set automatically in CI environments
|
195 |
|
196 | (Ask me for help if you're stuck)
|
197 |
|
198 |
|
199 |
|
200 | #### Usage with CLI
|
201 |
|
202 |
|
203 |
|
204 | 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.
|
205 |
|
206 | ```sh
|
207 | bundlesize -f "dist/*.js" -s 20kB
|
208 | ```
|
209 |
|
210 | For more granular configuration, we recommend configuring it in the `package.json` (documented above).
|
211 |
|
212 |
|
213 |
|
214 | #### Like it?
|
215 |
|
216 | :star: this repo
|
217 |
|
218 |
|
219 |
|
220 | #### How to contribute?
|
221 |
|
222 | - [CONTRIBUTING.md](CONTRIBUTING.md)
|
223 |
|
224 |
|
225 |
|
226 | #### Featured on [Totally tooling tips](https://www.youtube.com/watch?v=Da6VxdGU2Ig) and [Chrome Dev Summit](https://www.youtube.com/watch?v=_srJ7eHS3IM)!!
|
227 |
|
228 | <a href="https://www.youtube.com/watch?v=Da6VxdGU2Ig">
|
229 | <img height="200px" src="https://i.ytimg.com/vi/Da6VxdGU2Ig/hqdefault.jpg?sqp=-oaymwEXCNACELwBSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLAAfWzQIMvjH0TIzkAhi-114DIHPQ"/>
|
230 | </a>
|
231 | <a href="https://www.youtube.com/watch?v=_srJ7eHS3IM">
|
232 | <img height="200px" src="https://cdn.rawgit.com/siddharthkp/bundlesize/master/art/chromedevsummit.png"/>
|
233 | </a>
|
234 |
|
235 |
|
236 |
|
237 | #### who uses bundlesize?
|
238 |
|
239 | - [bootstrap](https://github.com/twbs/bootstrap)
|
240 | - [lighthouse](https://github.com/GoogleChrome/lighthouse)
|
241 | - [styled-components](https://github.com/styled-components/styled-components)
|
242 | - [emotion](https://github.com/tkh44/emotion)
|
243 | - [glamorous](https://github.com/paypal/glamorous)
|
244 | - [Popper.js](https://github.com/FezVrasta/popper.js)
|
245 | - [react-apollo](https://github.com/apollographql/react-apollo)
|
246 | - [hyperapp](https://github.com/hyperapp/hyperapp)
|
247 | - [css-constructor](https://github.com/siddharthkp/css-constructor)
|
248 | - [redux-saga](https://github.com/redux-saga/redux-saga)
|
249 | - [micromodal](https://github.com/ghosh/micromodal)
|
250 | - [unistore](https://github.com/developit/unistore)
|
251 | - [ngxs](https://github.com/ngxs/store)
|
252 |
|
253 |
|
254 |
|
255 | #### TODO
|
256 |
|
257 | - Work with other CI tools
|
258 | - [AppVeyor](https://www.appveyor.com/) ([#234](https://github.com/siddharthkp/bundlesize/issues/234))
|
259 | - Automate setup (setting env_var)
|
260 |
|
261 |
|
262 |
|
263 | #### similar projects
|
264 |
|
265 | - [BuildSize](https://buildsize.org/) - GitHub App, no manual configuration required
|
266 | - [travis-weigh-in](https://github.com/danvk/travis-weigh-in) - Uses Python rather than Node.js
|
267 | - [size-limit](https://github.com/ai/size-limit) - Uses webpack, builds your files for you.
|
268 |
|
269 | ## Contributors
|
270 |
|
271 | This project exists thanks to all the people who contribute. [[Contribute]](CONTRIBUTING.md).
|
272 | <a href="graphs/contributors"><img src="https://opencollective.com/bundlesize/contributors.svg?width=890" /></a>
|
273 |
|
274 | #### license
|
275 |
|
276 | MIT © [siddharthkp](https://github.com/siddharthkp)
|