superMDguy / tuxi

✨ White glove service for your async needs
https://www.npmjs.com/package/tuxi
MIT License
14 stars 0 forks source link

Packaged versions seem bloated #4

Closed pearofducks closed 6 years ago

pearofducks commented 6 years ago

I was interested in using this in some projects, and would normally expect a library like this to be quite small (wretch is a good example), however the packaged versions are pretty large (0.22 is 66kb). Additionally the ES version is only 0.34kb smaller than the umd build, which I would not expect if everything was packaged correctly.

superMDguy commented 6 years ago

I looked into it, and found a couple of issues.

  1. I'm not currently minifying, since I assumed people would have that in their own pipelines. However, now that I'm thinking about it, it'd probably be good to minify, and possibly do ES5 transpilation as well so it can be easily used without a webpack configuration. This might not be best for everyone, though, so I'll investigate the ways to ship both a minified ES5 version and an unminified build.
  1. The argument validation library I'm using ow is really heavy, and takes up most of the space. I'll look into lighter alternatives.

Taking out ow and minifying reduced the ES build size to 4kb, which feels a lot better. There's definitely still room for improvement though.

pearofducks commented 6 years ago

4kb is definitely an improvement :) Nice!

superMDguy commented 6 years ago

I ended up deciding on 3 builds:

  1. A 3.1kb (1.2kb gzipped) babel transpiled and minified IIFE build meant for being used from a script tag, probably via https://unpkg.com.
  2. A 7.6kb ES build meant for use with build tools like webpack, so it's not transpiled or minified at all.
  3. A 8.2kb babel transpiled CommonJS build, meant for use with Node. I decided to transpile since object rest spread, which I use, didn't show up until v8.3 of node, which is still relatively new.

The vue plugin is also now separate from the main codebase (see #3). It's available as a minified UMD build, which is only 360 bytes.