feat: support modern bundlers browser mode #24
Merged
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 is based on #13 but far less ambitious.
get-it
,rxjs
etc stays external).node
specificpkg.exports
.What is the point of this PR then?
It's to add a
pkg.exports.browsers
so that browser targeted bundling works in modern bundlers that doesn't supportpkg.browser
.What about ESM?
This PR improves that story slightly, not because the generated
sanityClient.browser.mjs
isESM
formatted, but only becauseesbuild
that generates it understandspkg.browsers
and makes sure to usesrc/http/browserMiddleware.js
instead ofsrc/http/nodeMiddleware.js
.This means that bundlers that are currently failing to build
@sanity/client
due to it attempting to bundleget-it/lib-node/middleware/*
and its dependencies, such as skypack:will now start working again with this PR.
I'll revisit #13 once all the upstream deps are ESM. That includes the
node
part of it as I need more time testing node 16 and its different modes with the newpkg.exports.node
to fully understand how it works and how we should wield it.