Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
The
rhea
package includes a browserified bundle in itsdist
folder that can be used to run rhea in a browser. This change updates thepackage.json
to use thebrowser
field so that bundlers (webpack for example) understand how to transform the node.js code when creating a JavaScript bundle.Motivation
This change reduces the friction for dependent libraries to support being used in browser environments. Currently, a library that depends on
rhea
would need to create a browser bundle and distribute that as well. This makes the dependent library depend on an exact version ofrhea
(in the browser build) even if its package.json specifies a range, which also means a new version of the dependent library needs to be released anytimerhea
is updated.Testing
One way to test how this change impacts bundler tools is to create a new npm project that depends on
rhea
and imports it, then create a bundle using a bundler. I tested using webpack/webpack-cli.index.js
Output before changes
Output after changes
I also tested these changes using our library that has
rhea
as a transitive dependency and was able to send and receive messages using websockets.Additional Info
Link to the package browser field spec: https://github.com/defunctzombie/package-browser-field-spec
Setting fs/net/tls to
false
makes it so bundlers will return an empty object when they encounter one of these imports. This looks consistent with what's happening in the browserified bundle that's distributed.