Skip to content
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 #19444

Open
4 tasks done
petebacondarwin opened this issue Feb 17, 2025 · 1 comment
Open
4 tasks done

Support resolve.alias per environment in Environments API #19444

petebacondarwin opened this issue Feb 17, 2025 · 1 comment

Comments

@petebacondarwin
Copy link

Description

The fix for #17582 was reverted so we should re-open it - but it is currently locked, so I thought I'd just create a new one to restart the conversation.

Not enabling per-environment aliasing creates a lot of friction as we move into a Vite Environment world where it is quite likely that each environment would need to alias imports differently depending upon the Environment it is targeting.

For the Cloudflare Vite Plugin, the obvious example is polyfilling Node.js APIs. Our plugin needs to alias some Node.js APIs to polyfills but this is not appropriate for the client environment, nor for other possible environments running on different backends (e.g. Node.js itself). See https://github.com/cloudflare/workers-sdk/blob/ed3bc2f3be45be55d20299ed3f481e75c63ba285/packages/vite-plugin-cloudflare/src/node-js-compat.ts#L77-L86

The current workaround is to alias these APIs to a virtual module, which is then processed in a resolveId() hook. But not only does this add complexity to the plugin, making it harder to understand, debug and maintain, it also doesn't appear to work well with pre-bundling of dependencies, where the id are not being resolved during the import analysis stage, since the pre-bundler is using a "top-level configuration" which doesn't trigger the plugin's resolve hook.

Suggested solution

The solution proposed in #17582 was to allow aliases to be provided per-environment. But in #18005 it was said that "it isn't clear if this option should be per-environment, as it may require other tools reading Vite aliases to be aware of environments."

So it is not clear to me what the solution is, but also why per-environment aliases are different to other per-environment options.

How can we help with moving this feature forward?

Alternative

No response

Additional context

No response

Validations

@petebacondarwin
Copy link
Author

Actually, we have reworked out Node.js compat support not to need Vite aliases, so this is no longer a necessity for us.
Feel free to close if this is not something you want to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants