vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

feat: add vue to `resolve.dedupe`

Open shigma opened this issue 3 years ago • 3 comments

Developers who wants to extend the theme may use libraries depending on different versions of vue, causing client errors. Adding vue to resolve.dedupe can avoid such conditions.

shigma avatar Sep 17 '22 17:09 shigma

I don't think resolve.dedupe will work for us as we are using SSR + ESM builds. Also, I suppose one can create a vite.config.ts themselves and add this option there (along with SSR + CJS settings).

brc-dd avatar Sep 21 '22 16:09 brc-dd

I don't think resolve.dedupe will work for us as we are using SSR + ESM builds.

Multiple instances of vue may cause failure in development and result in multiple chunks in the bundle.

I suppose one can create a vite.config.ts themselves and add this option there (along with SSR + CJS settings).

So does vitepress support vite config out of the box? (One may would like to use vitepress together with other component libraries.)

shigma avatar Sep 21 '22 19:09 shigma

Multiple instances of vue may cause failure in development and result in multiple chunks in the bundle.

Yeah, I understood that part. But according to Vite's docs, that doesn't work on SSR + ESM builds (<-- that's what we are using here). One needs to use CJS mode for SSR for it to work. And regarding Vite config, yes it is supported.

brc-dd avatar Sep 21 '22 19:09 brc-dd

But according to Vite's docs, that doesn't work on SSR + ESM builds.

Well I see. So should I just remove resolve.dedupe from SSR builds and keep the others?

shigma avatar Sep 24 '22 19:09 shigma

Developers who wants to extend the theme may use libraries depending on different versions of vue

I think we should simply discourage users from using different versions of Vue...? What is the reason why you can't update the Vue version?

kiaking avatar Oct 20 '22 11:10 kiaking

@kiaking It is not about updating the vue version. Adding dependencies in a composite project may result in multiple instances of vue, something like root > vue and root > @vueuse/core > vue. This problem can be fixed but is sometimes hard to find out.

shigma avatar Oct 20 '22 14:10 shigma

So, seems like Vite 4 still has same behavior at the moment. Maybe we should simple document about this issue...? It might be simpler.

@brc-dd Do you happen to have any news on this topic? 👀

kiaking avatar Jan 27 '23 04:01 kiaking

@shigma Evan is currently looking into this problem. It's also an issue in Nuxt as well. While adding this option to Vite config is one way of solving it, but we're trying to fix the issues by looking into the problem deeper.

We're trying gather as much as reproduction here to see the actual cases. If you have reproduction code, please share. It would be super helpful 🙇

kiaking avatar Feb 24 '23 09:02 kiaking

Maybe only dedupe for client-side builds?

yyx990803 avatar Mar 13 '23 09:03 yyx990803

vue plugin already dedupes this for client builds now - https://github.com/vitejs/vite-plugin-vue/blob/69fb8c811d8fdbc7bdc968033834ddede59ee885/packages/plugin-vue/src/index.ts#L163

brc-dd avatar Sep 12 '23 05:09 brc-dd