-
-
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
Support resolve.alias
per environment in Environments API
#17582
Comments
A common way to resolve a import specifier to a different module depending on the environment is to use conditional cc @patak-dev https://nodejs.org/docs/v20.15.0/api/packages.html#community-conditions-definitions |
In fact I use Some context for this: a developer using my framework doesn't need to install anything to start a React app, using npx it's possible to just run You can even do this: Where the gist contains an RSC: export default function App() {
return (
<html lang="en">
<head>
<title>My App</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
);
} |
We intended to make @sapphi-red let me know if you see a problem with having |
Thanks @patak-dev PR is already in place at #17583, let me know if my proposed solution is viable or there's a better way. |
Ah, I missed the PR, I'll check it out. |
I see. I think it makes sense to use |
Closing as #17583 is merged. |
Description
As a developer using Vite I want to use the Environment API and different
resolve.alias
per environment so that the same module name resolves to different files (like different filename suffix) or an environment adds more alias as it needs to resolve some modules differently than the others. Currently this is only possible by creating new environment instances and patching theconfig
received increateEnvironment
. Also https://github.com/vitejs/vite/blob/v6/environment-api/packages/vite/src/node/idResolver.ts#L43 and https://github.com/vitejs/vite/blob/v6/environment-api/packages/vite/src/node/idResolver.ts#L77 TODO comments are suggesting this was already a consideration.Suggested solution
Create a facade
vite:alias
plugin, which proxies alias resolution requests to @rollup/plugin-alias instances based on the current environment or using the originalentries
whenresolve.alias
was not defined on the environment.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: