max-mapper / nets

nothing but nets. http client that works in node and browsers
http://npmjs.org/nets
101 stars 10 forks source link

possibility to leave out buffer for browserify build? #7

Open gr2m opened 9 years ago

gr2m commented 9 years ago

I've a little lib that is a wrapper of a REST API, and we use it both in browser and node. When I build it with browserify, ~90% of the code is Buffer. Can I somehow leave it out of the build, and do the encoding: undefined thing, at least for browser usage?

mattdesl commented 9 years ago

I really like nets but had the same problem -- the vast majority of my bundle was just Buffer, which was never even getting used.

If this is intended to be browser-first, it could act a bit more like xhr by defaulting to a string response and using ArrayBuffer instead of Buffer (in both node + browser). But there are some problems that might come from that... maybe it's better to just keep it as a separate module?

Also, there are some alternatives here which might be good (axios and superagent are both small)

https://github.com/zeke/npm-collection-http-clients

nichoth commented 8 years ago

+1

Use the package.json browser field & refactor the require statements so that only xhr is included in browserify bundles.


On the other hand, the user can just do

browserify --exclude buffer code.js > bundle.js