|
| 1 | +# @funboxteam/harold |
| 2 | + |
| 3 | +<img align="right" width="192" height="192" |
| 4 | + alt="Harold avatar: Sad emoji with a smile mask on a face" |
| 5 | + src="./logo.png"> |
| 6 | + |
| 7 | +[](https://www.npmjs.com/package/@funboxteam/harold) |
| 8 | + |
| 9 | +**Harold** is a CLI tool that compares frontend project bundles in size. |
| 10 | + |
| 11 | +[По-русски](./README.ru.md) |
| 12 | + |
| 13 | +## Rationale |
| 14 | + |
| 15 | +The bundle size of an average frontend project grows on every change. |
| 16 | + |
| 17 | +~~To feel the pain~~ To make it easier to measure & compare the project size while refactoring or updating the deps, |
| 18 | +we've built Harold. |
| 19 | + |
| 20 | +## Demo |
| 21 | + |
| 22 | +<img align="center" |
| 23 | + alt="Demo GIF" |
| 24 | + src="./demo.gif"> |
| 25 | + |
| 26 | +<small><i>The demo is accelerated. In real life setting up the dependencies and building a project takes forever.</i></small> |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +```bash |
| 31 | +npm install -g @funboxteam/harold |
| 32 | +``` |
| 33 | + |
| 34 | +## Commands |
| 35 | + |
| 36 | +### snapshot \[options\] |
| 37 | + |
| 38 | +Builds the project and takes the snapshot. |
| 39 | + |
| 40 | +Available options: |
| 41 | + |
| 42 | +- `-o, --output <path>` — sets the snapshot output path; default is `harold_snapshot_<date>_<time>.json`; |
| 43 | +- `-e, --exec <cmd>` — sets the building command; default is `NO_HASH=true npm run build-production`; |
| 44 | +- `-p, --path <path>` — sets the path of the build result directory, which will be used for snapshotting; |
| 45 | + default is `public`. |
| 46 | + |
| 47 | +### diff \<left\> \<right\> |
| 48 | + |
| 49 | +Compares the passed snapshots. |
| 50 | + |
| 51 | +### help |
| 52 | + |
| 53 | +Sends halp. |
| 54 | + |
| 55 | +## FAQ |
| 56 | + |
| 57 | +### How it works? |
| 58 | + |
| 59 | +When you take a snapshot, Harold runs the build command, waits until the project is building, then goes to the output |
| 60 | +directory and records the files' sizes. At the same time it creates the gzipped version of each file and records |
| 61 | +it's size too. After than it spits the snapshot — JSON file with all the data. |
| 62 | + |
| 63 | +Then, when you have two snapshots and run `harold diff first.json second.json` it compares the diff files and prints |
| 64 | +the overall comparison. |
| 65 | + |
| 66 | +<details> |
| 67 | + <summary>Usage example</summary> |
| 68 | + |
| 69 | + ```bash |
| 70 | + # Open your project folder |
| 71 | + $ cd ~/my-syper-kewl-project/ |
| 72 | + |
| 73 | + # Take the first snapshot |
| 74 | + $ harold snapshot -o before.json |
| 75 | + |
| 76 | + # Make some changes in the project |
| 77 | + |
| 78 | + # Take the second snapshot |
| 79 | + $ harold snapshot -o after.json |
| 80 | + |
| 81 | + # Compare them |
| 82 | + $ harold diff before.json after.json |
| 83 | + |
| 84 | + Snapshots: |
| 85 | + Left: 11/10/2020 6:30:56 PM • my-syper-kewl-project • master |
| 86 | + Right: 11/10/2020 6:45:13 PM • my-syper-kewl-project • improvement/framework-update |
| 87 | + |
| 88 | + Build time: |
| 89 | + 16 seconds slower (Left: 129 seconds, Right: 145 seconds) |
| 90 | + |
| 91 | + Diff by category: |
| 92 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 93 | + before after Changes |
| 94 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 95 | + JS 1.04 MB (270 kB) 1.12 MB (294 kB) +78.2 kB (+23.7 kB), +1 item |
| 96 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 97 | + JS (legacy) 1.07 MB (285 kB) 1.16 MB (314 kB) +90.6 kB (+28.6 kB), +1 item |
| 98 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 99 | + CSS 144 kB (23.4 kB) 144 kB (23.4 kB) No changes |
| 100 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 101 | + Images 5.26 MB (5.23 MB) 5.26 MB (5.23 MB) No changes |
| 102 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 103 | + Fonts 159 kB (159 kB) 159 kB (159 kB) No changes |
| 104 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 105 | + Videos 1.59 MB (1.58 MB) 1.59 MB (1.58 MB) No changes |
| 106 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 107 | + Other 127 kB (13.2 kB) 127 kB (13.3 kB) +364 B (+82 B) |
| 108 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 109 | + |
| 110 | + Total 9.4 MB (7.56 MB) 9.57 MB (7.61 MB) +169 kB (+52.4 kB), +2 items |
| 111 | + ———————————————————————————————————————————————————————————————————————————————————— |
| 112 | + |
| 113 | + Diff by files: |
| 114 | + m public: +169 kB (+52.4 kB) |
| 115 | + m public/10.js: +16 B (+4 B) |
| 116 | + m public/11.js: -20 B (-3 B) |
| 117 | + + public/12.js: 301 B (143 B) |
| 118 | + m public/3.js: +1.84 kB (+621 B) |
| 119 | + m public/app.js: +4.18 kB (+843 B) |
| 120 | + m public/legacy.10.js: +42 B (+18 B) |
| 121 | + + public/legacy.12.js: 513 B (148 B) |
| 122 | + m public/legacy.3.js: +1.9 kB (+634 B) |
| 123 | + m public/legacy.app.js: +6.83 kB (+1 kB) |
| 124 | + m public/legacy.vendor.js: +81.3 kB (+26.8 kB) |
| 125 | + m public/legacy.vendor.js.LICENSE: +182 B (+41 B) |
| 126 | + m public/vendor.js: +72.2 kB (+22.1 kB) |
| 127 | + m public/vendor.js.LICENSE: +182 B (+41 B) |
| 128 | + ``` |
| 129 | +</details> |
| 130 | + |
| 131 | +### What is `NO_HASH`? |
| 132 | + |
| 133 | +Modern frontend bundlers may add hashes to the filenames to improve caching. But Harold compares files using |
| 134 | +their names. To improve the diff quality you should set up your bundler the way that turns off hashes when `NO_HASH` set. |
| 135 | + |
| 136 | +Or you may just override the build command by passing `--exec` flag. |
| 137 | + |
| 138 | +### How to make a snapshot without building a project? |
| 139 | + |
| 140 | +Pass to `--exec` a fake command, such as `echo 1`. |
| 141 | + |
| 142 | +### What is “JS (legacy)”? |
| 143 | + |
| 144 | +Due to the variety of web browsers, nowadays frontenders have to support not only modern Chrome & Firefox, but also |
| 145 | +old dusty IE or Presto-based Opera. To make it easier for users with modern browsers to download assets, |
| 146 | +developers split the bundle on two parts: modern one & legacy one. The latter includes more polyfills, |
| 147 | +contains older JS syntax, etc. |
| 148 | + |
| 149 | +Harold expects that in the case of legacy bundle existence, its files will be named as `legacy.*.js`. If there're such |
| 150 | +files, their stat will appear in “JS (legacy)” row. |
| 151 | + |
| 152 | +## Credits |
| 153 | + |
| 154 | +The avatar for the project was made by [Igor Garybaldi](http://pandabanda.com/). |
| 155 | + |
| 156 | +[](https://funbox.ru) |
0 commit comments