Reputation: 491
I'm trying to use request library with browserify. I actually want to make API calls with the same code on a client and on a server.
I created a small example where I only require request.
test.js
var r = require('request');
Then I browserify it and examine the size with disc tool.
browserify test.js --full-paths --outfile discify/bundle.js && discify discify/bundle.js --output discify/disc.html
The size of the resulting bundle.js is almost 1.5 MB. 650 KB is request itself, 625 KB is browserify, and 156 KB is browserify-core.
So the questions are:
Upvotes: 1
Views: 455
Reputation: 17354
Offt, Request is huge!
I had a scan at everything, it looks like the reason that request forces browserify to require a bunch of its core stuff is because request heavily uses node.js apis which browserify shims for the browser. (Like crypto or process) which you probably only need for the backend (for Oauth or something that you cant do with a normal library).
Also, I don't think request works on the client, so you'll need another library for it - superagent/axios (both works on the server)
Or you can just use superagent/axios if you're simply doing easy http calls.
Or if you need it on the server but want to ignore it on the client (since it doesnt work on the client)
{
"name": "mypkg",
"version": "1.2.3",
"main": "main.js",
"browser": {
"request": false
}
}
Or if you're using gulp then
bundler.ignore('request');
Upvotes: 2