@@ -201,6 +201,7 @@ export async function createVitePressPlugin(
201
201
return processClientJS ( code , id )
202
202
}
203
203
if ( id . endsWith ( '.md' ) ) {
204
+ const relativePath = path . posix . relative ( srcDir , id )
204
205
// transform .md files into vueSrc so plugin-vue can handle it
205
206
const { vueSrc, deadLinks, includes, pageData } = await markdownToVue (
206
207
code ,
@@ -210,15 +211,14 @@ export async function createVitePressPlugin(
210
211
allDeadLinks . push ( ...deadLinks )
211
212
if ( includes . length ) {
212
213
includes . forEach ( ( i ) => {
213
- ; ( importerMap [ slash ( i ) ] ??= new Set ( ) ) . add ( id )
214
+ ; ( importerMap [ slash ( i ) ] ??= new Set ( ) ) . add ( relativePath )
214
215
this . addWatchFile ( i )
215
216
} )
216
217
}
217
218
if (
218
219
this . environment . mode === 'dev' &&
219
220
this . environment . name === 'client'
220
221
) {
221
- const relativePath = path . posix . relative ( srcDir , id )
222
222
const payload : PageDataPayload = {
223
223
path : `/${ siteConfig . rewrites . map [ relativePath ] || relativePath } ` ,
224
224
pageData
@@ -260,13 +260,13 @@ export async function createVitePressPlugin(
260
260
configDeps . forEach ( ( file ) => server . watcher . add ( file ) )
261
261
}
262
262
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 )
265
265
// restart server on theme file creation / deletion
266
- if ( themeRE . test ( file ) ) {
266
+ if ( themeRE . test ( relativePath ) ) {
267
267
siteConfig . logger . info (
268
268
c . green (
269
- `${ path . relative ( process . cwd ( ) , _file ) } ${ added ? 'created' : 'deleted' } , restarting server...\n`
269
+ `${ relativePath } ${ added ? 'created' : 'deleted' } , restarting server...\n`
270
270
) ,
271
271
{ clear : true , timestamp : true }
272
272
)
@@ -275,10 +275,10 @@ export async function createVitePressPlugin(
275
275
}
276
276
277
277
// 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 )
279
279
280
- if ( ! added && importerMap [ file ] ) {
281
- delete importerMap [ file ]
280
+ if ( ! added && importerMap [ relativePath ] ) {
281
+ delete importerMap [ relativePath ]
282
282
}
283
283
}
284
284
server . watcher
@@ -410,9 +410,11 @@ export async function createVitePressPlugin(
410
410
mod && modules . push ( mod )
411
411
}
412
412
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
+ )
416
418
mod && modules . push ( mod )
417
419
} )
418
420
0 commit comments