-
-
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
fix: avoid externalizing plugins that resolve to local files in monorepos #17323
base: main
Are you sure you want to change the base?
Conversation
Run & review this pull request in StackBlitz Codeflow. |
It is breaking one of our test because we use a |
If it's optimized, wouldn't the path come from |
The cache dir is at |
Isn't this about config bundling, so the optimizer shouldn't be in play here? The test fail is not too terrible I think and I'm ok with fixing the test. This will fix #5370, which (seems like) I also tried this solution in the past but had issues with |
Oh, you're right. Ok, ya, we can update the test then. Do you think it is safe to include this in 5.3? |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, astro, ladle, laravel, marko, previewjs, quasar, rakkas, unocss, vite-plugin-pwa, vite-plugin-react-swc, vite-plugin-svelte, vite-setup-catalogue, vitepress |
@patak-dev @bluwy Please also check #17286 as this is a similar idea to fix the same issue (#5370), but specifically uses tsconfig paths. Might be a more robust solution as it requires the tsconfig to be setup correctly for it to work. Might also be a sledgehammer to crack a nut :) Either way would be good to get eyes on it. |
@garydex I've replied in the other PR About the ecosystem-ci results, seems like it does break a few downstream frameworks, and perhaps we should move this to the next major. |
Hm yeah, the dirname/filename issue is indeed unfortunate.
Would that work? We would end up with -- Edit: problems I see with this:
|
@bluwy @patak-dev Will this be targeted to v6? Would be great to have the untranspiled monorepos config working. |
Though the log is not available now, when I checked it last time, |
Context
Vite currently bundles the config file during development using ESBuild and all the relative imports are marked as "no external" because they are not matched in this regex, meaning that the imported code is read and bundled in the config.
This is great because it allows reloading the imported local plugins without restarting the process by calling
viteDevServer.restart()
. Otherwise, Node would cache the external imports (import cache) and wouldn't reload the code even if it changes.Problem
We have a few plugins in a monorepo together with a project template and we'd like to reload the plugins in the template dev server when they change. The problem is that the template is importing the local plugins using NPM workspaces (e.g. published NPM name
@shopify/hydrogen/vite
) instead of relative paths like../../packages/hydrogen/dist/plugin.js
.Therefore, our plugins are treated as external imports and Node's import cache makes it impossible to reload the plugin without restarting the whole dev server process.
Changes
Vite already follow symlinks in monorepos for in-app dependencies so I think it would be more consistent if it did the same for plugins in the config file. This PR makes it so imports that resolve to local files are not marked as external anymore.
I'm not sure if this is the correct fix so please let me know what you think.