Skip to content

Commit

Permalink
fix: HMR for style blocks inside markdown (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Apr 16, 2024
1 parent 97f3baa commit b2dc044
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions packages/slidev/node/vite/loaders.ts
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
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

0 comments on commit b2dc044

Please sign in to comment.