node browserify for node core libraries

青春壹個敷衍的年華 提交于 2019-12-10 15:33:45

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/17914810/node-browserify-for-node-core-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!