Skip to content

Commit

Permalink
fix: vue hmr (#1094)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
sxzz and antfu authored Aug 26, 2023
1 parent dc30818 commit 5ce92a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
24 changes: 4 additions & 20 deletions packages/slidev/node/plugins/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,10 @@ export function createSlidesLoader(
if (hmrPages.size > 0)
moduleIds.add('/@slidev/titles.md')

const vueModules = (
await Promise.all(
Array.from(hmrPages).map(async (i) => {
const file = `${slidePrefix}${i + 1}.md`
try {
const md = await transformMarkdown((await (<any>MarkdownPlugin.transform)(newData.slides[i]?.content, file)).code, i, newData)
const handleHotUpdate = 'handler' in VuePlugin.handleHotUpdate! ? VuePlugin.handleHotUpdate!.handler : VuePlugin.handleHotUpdate!
return await handleHotUpdate({
...ctx,
modules: Array.from(ctx.server.moduleGraph.getModulesByFile(file) || []),
file,
read() { return md },
})
}
catch (e) {
console.error('[Slidev] failed to send HMR', e)
}
}),
)
).flatMap(i => i || [])
const vueModules = Array.from(hmrPages).map(i =>
ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.md`),
)

hmrPages.clear()

const moduleEntries = [
Expand Down
2 changes: 1 addition & 1 deletion packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@slidev/client": "workspace:*",
"@slidev/parser": "workspace:*",
"@slidev/types": "workspace:*",
"@vitejs/plugin-vue": "4.3.1",
"@vitejs/plugin-vue": "^4.3.3",
"@vitejs/plugin-vue-jsx": "^3.0.2",
"@windicss/config": "^1.9.1",
"cli-progress": "^3.12.0",
Expand Down
25 changes: 9 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ce92a0

Please sign in to comment.