split URL to node/browser versions and add brower mapping to package.json #1
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.
This PR shows how get around some of the bundling issues. Since browsers don't have access to the node.js modules, what we end up doing to keep bundlers happy is create runtime-specific versions of the APIs we need.
This looks at URL specifically. We're lucky in that both node.js and browsers support a URL parser with the same API, but in browsers we access the API via a global. So what I've done is created
utils/url.ts
andutils/url.browser.ts
that both just re-export the URL object. Then inpackage.json
, I added a mapping in thebrowser
field so bundlers know that if they are targetting a browser, they should pull in the browser version ofurl
instead of the node.js version.You may need to do this for other APIs too, but this at least gets the karma tests starting to run versus just throwing a TypeError.