-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support cjs noExternal in SSR dev, fix #2579 #8430
Conversation
We could also automatically include every explicit (type 'string') dependency in |
Wow, this will make a lot of people very happy!!
This probably works well enough with one caveat. You can specify values in (On a related note, I think the precedence of |
Yes, in the PR I'm only auto including every
I already changed it to work as you expect in v3, see
I kind of consider this a fix more than a breaking change. An explicit external should take precedence over noExternal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the PR only is currently only optimizing dependencies that are both marked as
noExternal
and explicitly added to theoptimizeDeps.include
. I think this may be enough, as it acts more as a way to overcome issues with some dependencies.
I think this makes sense to me. Perhaps we can have a separate PR to improve ssrLoadModule
to error on CJS code and recommend this option, but otherwise it's good that users have a way around the issue.
Just for reference, the logic now auto include each explicit @bluwy maybe we should merge this PR so people can test it in an alpha. Worst case we disable the feature if we decide in a team meeting that this isn't a good idea. What do you think? |
Ah I didn't notice that. Yeah I think it should be fine then. +1 on merging this for alpha |
We discussed this PR with Evan and we are good to merge it. Let's get it out in the beta so we can resolve #2579 |
Saus needs an option to disable @patak-dev What would you prefer the option name be? |
Oh it appears that I just have to not call vite/packages/vite/src/node/server/index.ts Lines 369 to 371 in 0a69985
But it looks like |
Description
Fix #2579
See the issue for context, in particular, this comment:
#2579 (comment)
After the latest changes to use the esbuild deps optimizer during build, the only place where wasn't still used was during dev ssr.
If a dependency like 'cookie' that is using
exports
instead ofmodule.exports
and was marked asnoExternal
, Vite couldn't process it during dev ssr. The dependency could be marked asexternal
but there may be cases where the user would like to generate a bundled SSR build.This PR creates a dedicated optimized deps cache for dev ssr when the server starts, and allow these dependencies that are now working well during build to also work during dev. We don't yet have a discovery mechanism of deps during dev ssr and adding it would also imply adding a way to invalidate a ssrLoadModule request and retry it if the optimized deps changed (equivalent to a full reload in the browser). So the PR only is currently only optimizing dependencies that are both marked as
noExternal
and explicitly added to theoptimizeDeps.include
. I think this may be enough, as it acts more as a way to overcome issues with some dependencies.Sending the PR as is to start the discussion, I still don't know if this is the best approach moving forward but it may be a way out of one of the most voted issues in Vite and it is also good that dev ssr for these deps will be closer to build ssr.
There isn't a config option to disable this new optimization step, I think we may not need one here.
What is the purpose of this pull request?