migrate to hotUpdate

pull/4525/head
Divyansh Singh 7 months ago
parent de2ce4e8fb
commit 08fab8aca5

@ -3,7 +3,6 @@ import c from 'picocolors'
import { import {
mergeConfig, mergeConfig,
searchForWorkspaceRoot, searchForWorkspaceRoot,
type ModuleNode,
type Plugin, type Plugin,
type ResolvedConfig, type ResolvedConfig,
type Rollup, type Rollup,
@ -424,16 +423,16 @@ export async function createVitePressPlugin(
const hmrFix: Plugin = { const hmrFix: Plugin = {
name: 'vitepress:hmr-fix', name: 'vitepress:hmr-fix',
async handleHotUpdate({ file, server, modules }) { async hotUpdate({ file, server, modules }) {
const importers = [...(importerMap[slash(file)] || [])] const importers = [...(importerMap[slash(file)] || [])]
if (importers.length > 0) { if (importers.length > 0) {
return [ return [
...modules, ...modules,
...importers.map((id) => { ...importers.map((id) => {
clearCache(slash(path.relative(srcDir, id))) clearCache(slash(path.relative(srcDir, id)))
return server.moduleGraph.getModuleById(id) return this.environment.moduleGraph.getModuleById(id)
}) })
].filter(Boolean) as ModuleNode[] ].filter((mod) => mod !== undefined)
} }
} }
} }

@ -3,9 +3,9 @@ import path from 'node:path'
import c from 'picocolors' import c from 'picocolors'
import { glob } from 'tinyglobby' import { glob } from 'tinyglobby'
import { import {
EnvironmentModuleNode,
loadConfigFromFile, loadConfigFromFile,
normalizePath, normalizePath,
type EnvironmentModuleNode,
type Logger, type Logger,
type Plugin type Plugin
} from 'vite' } from 'vite'

@ -198,7 +198,7 @@ export async function localSearchPlugin(
} }
}, },
async handleHotUpdate({ file }) { async hotUpdate({ file }) {
if (file.endsWith('.md')) { if (file.endsWith('.md')) {
await indexFile(file) await indexFile(file)
debug('🔍️ Updated', file) debug('🔍️ Updated', file)

Loading…
Cancel
Save