Use native EventSource in browsers
Hi,
this PR adds a browser field to package.json, with a browser.js that re-exports window.EventSource in CommonJS format. This makes the package easily compatible with CommonJS based bundlers (e.g. vite).
👎🏻 use standard exports field instead.
I don't think this is a decision to be taken lightly.
Personally, I feel that this module is not a great fit for the browser even when using polyfills for http, https, url and similar, since it adds a significant amount of code and complexity. Having said that, this PR would be a big breaking change, and will only work in browsers with a native EventSource implementation. While that is thankfully the case for most modern browsers, it is not a drop-in replacement. For instance, the second argument to the constructor does not provide any way to specify headers in the browser, so it creates a mismatch in behavior between node and the browser which is annoying to deal with.