5 ms·
Why is Babel overkill? It lets you write your code in ES6, which is a huge benefit for many reasons.
by zeroxfe 10y ago
Why is Babel overkill? It lets you write your code in ES6, which is a huge benefit for many reasons.
- nathancahill 10y agoThe fact that it's delivering 140 lines in 5.5kb. That's a lot of bloat! There are ways to write code in ES6 without that (see sibling responses).
- Heqx 10y agoHey, author here. I'm very open to ideas to reduce bloat. It's 140 SLOC and ~1.1kb gzipped without lodash/throttle. I considered writing my own throttle, but wanted something more battle-tested. Does Rollup produce a more efficient bundle in your experience?
- andreasklinger 10y agorollup can only load the functions of lodash you actually use into your bundle
- tdumitrescu 10y agoSo can lodash. That's what the author is doing here by using import throttle from 'lodash/throttle'; rather than import { throttle } from 'lodash';
- yagami_san 10y agoJust use https://www.npmjs.com/package/lodash.throttle https://www.npmjs.com/package/lodash.throttle
- Heqx 10y agoCan you point me to an explanation of the differences between the 'lodash.throttle' module and importing 'lodash/throttle'?
- freditup 10y agoYou should get about the same results using a bundler. Perhaps the lodash.throttle package is for reducing `npm install` time or reducing bloat if you check in your node modules?
- jdd 10y agolodash.throttle is a standalone zero-dependency package of just the throttle module. The `lodash` package is a collection of modules one of which is `lodash/throttle`. You can generally get smaller bundles using `lodash/xyz` modules over the `lodash.xyz` packages because of plugins like: https://github.com/lodash/babel-plugin-lodash https://github.com/lodash/babel-plugin-lodash https://github.com/lodash/lodash-webpack-plugin https://github.com/lodash/lodash-webpack-plugin Though in the future lodash-webpack-plugin may support `lodash.xyz` packages too.
- nathancahill 10y agoOP is using that already.
- nathancahill 10y agoNot sure why I was downvoted, I think it's a valid point. To prove it, here's the functionality of your library in ES5 with a naive throttle function: https://gist.github.com/nathancahill/f7ea239306737f2075a94de33881dc2e https://gist.github.com/nathancahill/f7ea239306737f2075a94de... Minified (1.49kb) and gzipped (677b). Whether lodash functions should be used instead of naive functions is up for debate. My opinion is if the lodash functions are 5x the size of the entire library, it's probably best to not include it, or to include it as a build option (if the user's project already includes lodash for example).
- jdd 10y agoNo worries, lodash/debounce can be reduced further with babel+webpack plugins. Assuming the current setup of babel+webpack the difference between your naive version is just ~0.5 kB.
- nathancahill 10y agoWhich still doubles the size of the library: ~0.6kb to ~1.1kb. So while it's just half a kilobyte, do that over and over, with nested dependencies and it really adds up.
- Ralfp 10y agoBut if your entire project uses Babel, those 140 lines will already be in your code and thus won't be added.
- zeroxfe 10y agoThe only sibling response is rollupjs, which replaces webpack with ES6 import syntax. You still need bablel for the rest of the ES6 syntax.
- epidemian 10y ago> You still need bablel for the rest of the ES6 syntax. Or Bublé[1] ;) which i've found to be much faster than Babel, even for relatively small codebases (~ a couple thousand LoC). [1]: https://gitlab.com/Rich-Harris/buble https://gitlab.com/Rich-Harris/buble