@@ -35,6 +35,7 @@ declare module 'vite' {
35
35
}
36
36
}
37
37
38
+ const themeRE = / \/ \. v i t e p r e s s \/ t h e m e \/ i n d e x \. ( m | c ) ? ( j | t ) s $ /
38
39
const hashRE = / \. ( \w + ) \. j s $ /
39
40
const staticInjectMarkerRE =
40
41
/ \b ( c o n s t _ h o i s t e d _ \d + = \/ \* (?: # | @ ) _ _ P U R E _ _ \* \/ \s * c r e a t e S t a t i c V N o d e ) \( " ( .* ) " , ( \d + ) \) / g
@@ -225,16 +226,32 @@ export async function createVitePressPlugin(
225
226
configDeps . forEach ( ( file ) => server . watcher . add ( file ) )
226
227
}
227
228
228
- // update pages, dynamicRoutes and rewrites on md file add / deletion
229
- const onFileAddDelete = async ( file : string ) => {
229
+ const onFileAddDelete = async ( added : boolean , file : string ) => {
230
+ // restart server on theme file creation / deletion
231
+ if ( themeRE . test ( slash ( file ) ) ) {
232
+ siteConfig . logger . info (
233
+ c . green (
234
+ `${ path . relative ( process . cwd ( ) , file ) } ${
235
+ added ? 'created' : 'deleted'
236
+ } , restarting server...\n`
237
+ ) ,
238
+ { clear : true , timestamp : true }
239
+ )
240
+
241
+ await recreateServer ?.( )
242
+ }
243
+
244
+ // update pages, dynamicRoutes and rewrites on md file creation / deletion
230
245
if ( file . endsWith ( '.md' ) ) {
231
246
Object . assign (
232
247
siteConfig ,
233
248
await resolvePages ( siteConfig . srcDir , siteConfig . userConfig )
234
249
)
235
250
}
236
251
}
237
- server . watcher . on ( 'add' , onFileAddDelete ) . on ( 'unlink' , onFileAddDelete )
252
+ server . watcher
253
+ . on ( 'add' , onFileAddDelete . bind ( null , true ) )
254
+ . on ( 'unlink' , onFileAddDelete . bind ( null , false ) )
238
255
239
256
// serve our index.html after vite history fallback
240
257
return ( ) => {
0 commit comments