Closed sunziping2016 closed 3 years ago
This is too vague without actual code. If you can provide a minimal demo that will help.
In markdown.ts, I try to return different code based on query string. Thus, the exportExcerpt and the exportContent may refer to the same file, which will cause @vitejs/plugin-vue
treat them as one item. To overcome this, I wrapped @vitejs/plugin-vue
in vueWrapper.ts and change the id passed to the inner @vitejs/plugin-vue
. But I think this solution may be too dirty. Is there any better solution?
Hmm, this is like virtual module inception... I think the only way is to use actually different file names. e.g. instead of foo.md?pageData
, use foo.pageData.md
instead. This is essentially what you are doing in the wrapper, but if you generate these filenames directly and parse for them instead of queries in your markdown loader, you can avoid hacking the vue plugin.
Hmm, this is like virtual module inception... I think the only way is to use actually different file names. e.g. instead of
foo.md?pageData
, usefoo.pageData.md
instead. This is essentially what you are doing in the wrapper, but if you generate these filenames directly and parse for them instead of queries in your markdown loader, you can avoid hacking the vue plugin.
So is it possible to hot reload a virtual module when the file changed? It seems moduleGraph.ts doesn't provide API for doing this.
Oh yeah, using different filenames means they won't be linked to the original file for HMR. I guess there's no clean way around this then.
Is your feature request related to a problem? Please describe. I am now implementing a blog generator with Vite, which is similar to VitePress. I want to generate two Vue components from single Markdown file. One is the excerpt, the other is the full content. There may exist two solutions for that:
@vitejs/plugin-vue
seems not well prepared for this situation. I did some dirty hacks (e.g. replacing_sfc_main.__hmrId
), and I am still trying. If@vitejs/plugin-vue
can generate different__hmrId
andhandleHotUpdate
can deal with multiplemainModule
anddescriptorCache
can store muliple cache, it would be fine.Describe the solution you'd like The two bold text in the above description is the solution I'd like.
Describe alternatives you've considered I am tring to do the dirty hacks. And I will really be pleased if there already exists some solution that I've missed. Sorry for bother you.