@@ -201,6 +201,7 @@ export async function createVitePressPlugin(
201201 return processClientJS ( code , id )
202202 }
203203 if ( id . endsWith ( '.md' ) ) {
204+ const relativePath = path . posix . relative ( srcDir , id )
204205 // transform .md files into vueSrc so plugin-vue can handle it
205206 const { vueSrc, deadLinks, includes, pageData } = await markdownToVue (
206207 code ,
@@ -210,15 +211,14 @@ export async function createVitePressPlugin(
210211 allDeadLinks . push ( ...deadLinks )
211212 if ( includes . length ) {
212213 includes . forEach ( ( i ) => {
213- ; ( importerMap [ slash ( i ) ] ??= new Set ( ) ) . add ( id )
214+ ; ( importerMap [ slash ( i ) ] ??= new Set ( ) ) . add ( relativePath )
214215 this . addWatchFile ( i )
215216 } )
216217 }
217218 if (
218219 this . environment . mode === 'dev' &&
219220 this . environment . name === 'client'
220221 ) {
221- const relativePath = path . posix . relative ( srcDir , id )
222222 const payload : PageDataPayload = {
223223 path : `/${ siteConfig . rewrites . map [ relativePath ] || relativePath } ` ,
224224 pageData
@@ -260,13 +260,13 @@ export async function createVitePressPlugin(
260260 configDeps . forEach ( ( file ) => server . watcher . add ( file ) )
261261 }
262262
263- const onFileAddDelete = async ( added : boolean , _file : string ) => {
264- const file = slash ( _file )
263+ const onFileAddDelete = async ( added : boolean , file : string ) => {
264+ const relativePath = path . posix . relative ( srcDir , file )
265265 // restart server on theme file creation / deletion
266- if ( themeRE . test ( file ) ) {
266+ if ( themeRE . test ( relativePath ) ) {
267267 siteConfig . logger . info (
268268 c . green (
269- `${ path . relative ( process . cwd ( ) , _file ) } ${ added ? 'created' : 'deleted' } , restarting server...\n`
269+ `${ relativePath } ${ added ? 'created' : 'deleted' } , restarting server...\n`
270270 ) ,
271271 { clear : true , timestamp : true }
272272 )
@@ -275,10 +275,10 @@ export async function createVitePressPlugin(
275275 }
276276
277277 // update pages, dynamicRoutes and rewrites on md file creation / deletion
278- if ( file . endsWith ( '.md' ) ) await resolvePages ( siteConfig )
278+ if ( relativePath . endsWith ( '.md' ) ) await resolvePages ( siteConfig )
279279
280- if ( ! added && importerMap [ file ] ) {
281- delete importerMap [ file ]
280+ if ( ! added && importerMap [ relativePath ] ) {
281+ delete importerMap [ relativePath ]
282282 }
283283 }
284284 server . watcher
@@ -410,9 +410,11 @@ export async function createVitePressPlugin(
410410 mod && modules . push ( mod )
411411 }
412412
413- importerMap [ slash ( file ) ] ?. forEach ( ( importer ) => {
414- clearCache ( importer )
415- const mod = this . environment . moduleGraph . getModuleById ( importer )
413+ importerMap [ slash ( file ) ] ?. forEach ( ( relativePath ) => {
414+ clearCache ( relativePath )
415+ const mod = this . environment . moduleGraph . getModuleById (
416+ path . posix . join ( srcDir , relativePath )
417+ )
416418 mod && modules . push ( mod )
417419 } )
418420
0 commit comments