You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a facade vite:alias plugin, which proxies alias resolution requests to @rollup/plugin-alias instances based on the current environment or using the original entries when resolve.alias was not defined on the environment.
A common way to resolve a import specifier to a different module depending on the environment is to use conditional exports/imports. For example, RSC uses it like this.
Would that cover your needs?
In fact I use resolve.alias for React, aliasing react, react-dom and react-server-dom-webpack exports to absolute paths in case of client/ssr environments, but not for rsc. I know my use case is niche and unconventional, still it just works this way. But during trying to clean up and strip down my Vite config in my React meta-framework I noticed that while alias is part of EnvironmentResolveOptions at https://github.com/vitejs/vite/blob/v6/environment-api/packages/vite/src/node/config.ts#L221, the environment is not using this, just from the server config and also noticed the TODO comments. See playground test in PR at https://github.com/vitejs/vite/blob/f217c539e162bd6106bc8606b601f71615fcf3b1/playground/environment-alias/vite.config.js. Sometimes changing the exports of a package is not possible as the developer's requirements is not the same as the package maintainer's.
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 npx @lazarv/react-server ./App.jsx and it just works, without any other packages installed or the developer just need add my framework as dependency and nothing else. React is resolved from inside the framework.
You can even do this: curl https://gist.githubusercontent.com/lazarv/23ea9a77f7061f3086a7516d3e7edd2d/raw/4b621ea2a17fefcb9b690edd7edf57393a5da03f/App.jsx | npx @lazarv/react-server --open
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: