8 ms·
Babel and webpack are megaoverkill for this and account for a good chunk of the 2k gzipped size. The actual library code is barely 140SLOC. There's a lot of roo
by dmbass 10y ago
Babel and webpack are megaoverkill for this and account for a good chunk of the 2k gzipped size. The actual library code is barely 140SLOC. There's a lot of room for improvement if this is intended to be a real standalone library (vs. a webpack/babel test).
- johnhenry 10y agoI've found rollup, https://rollupjs.org/ https://rollupjs.org/, to be really useful for this.
- jonahx 10y agoThis looks nice. Is it as battle-tested as browserify?
- sotojuan 10y agoIt's fairly new but The Guardian uses it for all their JavaScript (the creator works there).
- JasonSage 10y agotl;dr—don't use rollup with large untested dependencies I've had projects that got really strange error messages when using rollup that completely went away when I switched back to Babel. One "issue" with rollup is that it is not 100% semantically correct. Neither is Babel in all cases, but the creator argues that if you're not following exact semantics now, you're relying on your tests to ensure proper behavior, so use something that is at least more minimal and keeps your bundle size down. So when you're writing code and bundling with rollup, you can pretty much ensure everything works fine, but as soon as you pull in an extensive third-party library you have no assurances that it has been tested with rollup and will work correctly in all cases. In the worst case, it will seem to work fine but in weird situations will actually error out. This was my experience with rollup.
- JasonSage 10y agoI should clarify on my above comment, in rollup the semantics don't matter as much but if you're using Bublé instead of Babel, the semantics may very well come into play. In either case, I didn't have luck on a project until I moved fully to webpack+Babel.
- deleted 10y ago[deleted]
- Eric_WVGG 10y agoI believe Waypoints also does this same thing, it's a fairly mature lib. https://github.com/imakewebthings/waypoints https://github.com/imakewebthings/waypoints kudos for in-view's demo page though
- deleted 10y ago[deleted]
- zeroxfe 10y agoWhy 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'?
- mbell 10y agoWebpack's runtime overhead is tiny, babel's varies based on what polyfills you need but very little is included here. Most of the code here is actually from lodash due to the use of `throttle`, not either of the projects you mentioned.
- joshkpeterson 10y agoThrottle seems key for something like this, too.