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

fix: HMR for style blocks inside markdown #1536

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/slidev/node/vite/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,17 @@ export function createSlidesLoader(
moduleIds.add(templateTitleRendererMd.id)

const vueModules = Array.from(hmrPages)
.flatMap(i => [
ctx.server.moduleGraph.getModuleById(`${VIRTUAL_SLIDE_PREFIX}${i + 1}.frontmatter`),
ctx.server.moduleGraph.getModuleById(`${VIRTUAL_SLIDE_PREFIX}${i + 1}.md`),
])
.flatMap((i) => {
const id = `${VIRTUAL_SLIDE_PREFIX}${i + 1}`
const frontmatter = ctx.server.moduleGraph.getModuleById(`${id}.frontmatter`)
const main = ctx.server.moduleGraph.getModuleById(`${id}.md`)
const styles = main ? [...main.clientImportedModules].find(m => m.id?.startsWith(`${id}.md?vue&type=style`)) : undefined
return [
frontmatter,
main,
styles,
]
})

hmrPages.clear()

Expand All @@ -316,7 +323,7 @@ export function createSlidesLoader(
},

resolveId(id) {
if (id.startsWith(VIRTUAL_SLIDE_PREFIX) || id.startsWith('/@slidev/'))
if (id.startsWith('/@slidev/'))
return id
return null
},
Expand Down
2 changes: 1 addition & 1 deletion packages/slidev/node/vite/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function createVuePlugin(
} = pluginOptions

const VuePlugin = Vue({
include: [/\.vue$/, /\.md$/],
include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/, /\.md\?vue/],
exclude: [],
template: {
compilerOptions: {
Expand Down