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.
Description
Reworked #3121 as a feat.
#2996 and #3039 reworked the package resolution to ignore the
browser
field if the plugin is running in ssr mode.See @frandiox comment, if the target is webworker (ie cloudflare workers) then the
browser
field should be respected even in ssr mode.There is a new config option
ssr.target
:We already have a
build.target
but if we reuse it, the users will be forced to modify this option depending on building for the web or usingbuild --ssr
. I think it makes sense to be able to define both in the config file.A
targetWeb
param to the resolve methods instead of the previousssr
one (I think thattargetWeb
is better here thantargetNode
to avoid the need to negate it when using it). In the resolve plugin:#2996 #3039 didn't introduce a regression for Web Workers, because the target was implicitly Node until this point. So they are both fixes for the Node ssr server.
This PR allows ecosystem solutions like vitedge to resolve the browser field as before. There may be other differences that we need to take into account when
ssr.target
iswebworker
, but for @frandiox Vite was working without issues before these changes. I think there is the need for extra configuration that may now be included as default when targeting webworkers. For example theresolve.mainFields
default. I think these could be added in future PRs. As the SSR feature is still labeled experimental,ssr.target
should also be considered experimental.What is the purpose of this pull request?