user1028880
user1028880

Reputation:

node browserify for node core libraries

This is a question just to confirm my understanding of node browserify.

substack/node-browserify says:

compatibility: Many npm modules that don't do IO will just work after being browserified. Others take more work. Many node built-in modules have been wrapped to work in the browser, but only when you explicitly require() or use their functionality.

--

get browser versions of the node core libraries events, stream, path, url, assert, buffer, util, querystring, http, vm, and crypto when you require() them

Does node browserify takes the source-code of the node build-in modules, and construct a bundled file; by selecting the current working NVM version properly?

Actually, I used browserify first time with maxogden/websocket-stream, and works amazingly.

Upvotes: 3

Views: 2611

Answers (1)

Thorsten Lorenz
Thorsten Lorenz

Reputation: 11847

No, it does not use node core modules in their initial form. Certain functions don't make sense in the browser at all or at least have to be adapted to make sense.

Instead browserify uses a module called browser-builtins in order to provide meaningful alternatives.

Inspecting the package.json file of this module you can see which core modules are provided by external packages.

The remaining ones come from here.

As you can see, some modules like fs don't make sense in the browser (at least not at this point).

Others however can easily be adapted to work in the browser.

Edit:

The above is not entirely true anymore. In the spirit of modularity the latest browserify no longer depends on browser-builtins, but instead each module shim is published separately.

For more information please review builtins.js and package.json

Upvotes: 5

Related Questions