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

Optimize a dependency aliased to an absolute path #1302

Closed
aleclarson opened this issue Jan 2, 2021 · 8 comments
Closed

Optimize a dependency aliased to an absolute path #1302

aleclarson opened this issue Jan 2, 2021 · 8 comments

Comments

@aleclarson
Copy link
Member

I need to optimize react since it uses CommonJS modules, but I also need to force all packages to use the same copy of React, which I accomplish via the alias option in my Vite config. Unfortunately, these two needs are in conflict, as the import rewriter doesn't check if an absolute path is optimized.

@aleclarson
Copy link
Member Author

I also need to force all packages to use the same copy of React

For more context, my project is linked to local clones of packages that also depend on React.

@aleclarson
Copy link
Member Author

aleclarson commented Jan 2, 2021

Perhaps, instead of using alias, it would be easier (from Vite's perspective) to use a load hook for the redirection.

edit: Hmm, I don't think this is a viable workaround, as the optimizer has already duplicated React by the time my load hook runs. And there's no way to inject a load hook into the optimizer.

@yyx990803
Copy link
Member

I think we can add a dedupe option to force react to always be resolved using your project root as basedir?

@aleclarson
Copy link
Member Author

Sounds good to me. I was about to make a plugin for it, but built-in is better in this case.

@yyx990803
Copy link
Member

Wait, if a dependency is optimized it already always uses the optimized version without the need for an alias.

@aleclarson
Copy link
Member Author

The optimizer is duplicating React for me. I'll make a repro.

@aleclarson
Copy link
Member Author

@aleclarson
Copy link
Member Author

My current workaround: https://github.com/alloc/vite-plugin-dedupe

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants