-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: expose version at ConfigEnv #19355
base: main
Are you sure you want to change the base?
Conversation
Could you provide a reproduction of when |
Indeed. And that's, for example, one reason why React allows only one React instance. Vike also does this but less strict: we allow multiple Vike instances but they all must be the same version. Having different versions of Vike within the same process is a no-go and Vike will throw an error and purposely break the app — precisely to avoid a mirad of issues that can arise from this. That said, for Vite, it's much less of an issue because most Vite plugins don't import that many things from I think whether Vite wants to go strict or loose is something the Vite team should decide. There are trade-offs. The upside of being strict is that it avoids issues, such as what this PR tries to workaround. The downside is that it's 1) a breaking change and 2) it can be annoying for the user to always have to ensure that the same Vite version is loaded. For example, if a Vite plugin wrongfully adds I don't know how much being strict would be an annoyance for Vite users, but I'd recommend following course of actions:
|
Why do you have If we need to expose a version via plugin interface, I'll prefer adding |
See vikejs/vike#2070 (comment). It's unrelated to this PR, see minimal reproduction that only depends on
I just checked and it seems like |
When developing Vite plugins you eventually need to test your plugin against different vite versions. @brillout is correct in saying that Need this feature badly - happy to find someones already worked on it! |
Description
import { version } from 'vite'
isn't reliable: because, with monorepos, it oftens returns the "wrong version" (it returns the version of the locally resolvedvite
, but not the version ofvite
that is actually running).This PR adds
ConfigEnv['version']
so that meta frameworks can check whether the user is using a supported Vite version.For example Vike ensures that the user is using a supported Vite version and shows a helpful error message if the user doesn't:
The only reliable solution I can think of is for Vite to expose its version to Vite plugins.
The earlier the version is exposed the better. For example, exposing the version as
ResolvedConfig['version']
would be too late: at that point Vike already uses functionalities of later Vite versions. Exposing the version overConfigEnv
has the advantage that the it's accessible early.Related PR: #8456.