@@ -33,22 +33,16 @@ const CONFIG_RESTART_FIELDS: (keyof SlidevConfig)[] = [
3333 'seoMeta' ,
3434]
3535
36- /**
37- * Files that triggers a restart when added or removed
38- */
39- const FILES_CREATE_RESTART = [
40- 'global-bottom.vue' ,
41- 'global-top.vue' ,
42- 'uno.config.js' ,
43- 'uno.config.ts' ,
44- 'unocss.config.js' ,
45- 'unocss.config.ts' ,
46- ]
47-
4836const FILES_CHANGE_RESTART = [
4937 'setup/shiki.ts' ,
5038 'setup/katex.ts' ,
5139 'setup/preparser.ts' ,
40+ 'setup/transformers.ts' ,
41+ 'setup/unocss.ts' ,
42+ 'setup/vite-plugins.ts' ,
43+ 'uno.config.ts' ,
44+ 'unocss.config.ts' ,
45+ 'vite.config.{js,ts,mjs,mts}' ,
5246]
5347
5448setupPreparser ( )
@@ -122,17 +116,17 @@ cli.command(
122116 let lastRemoteUrl : string | undefined
123117
124118 let restartTimer : ReturnType < typeof setTimeout > | undefined
125- function restartServer ( ) {
126- clearTimeout ( restartTimer ! )
119+ async function restartServer ( ) {
120+ await server ?. close ( )
121+ server = undefined
122+ clearTimeout ( restartTimer )
127123 restartTimer = setTimeout ( ( ) => {
128124 console . log ( yellow ( '\n restarting...\n' ) )
129125 initServer ( )
130126 } , 500 )
131127 }
132128
133129 async function initServer ( ) {
134- if ( server )
135- await server . close ( )
136130 const options = await resolveOptions ( { entry, remote, theme, inspect, base } , 'dev' )
137131 const host = remote !== undefined ? bind : 'localhost'
138132 port = userPort || await getPort ( {
@@ -210,6 +204,8 @@ cli.command(
210204 publicIp = await import ( 'public-ip' ) . then ( r => r . publicIpv4 ( ) )
211205
212206 lastRemoteUrl = printInfo ( options , port , base , remote , tunnelUrl , publicIp )
207+
208+ return options
213209 }
214210
215211 async function openTunnel ( port : number ) {
@@ -304,17 +300,18 @@ cli.command(
304300 } )
305301 }
306302
307- initServer ( )
303+ const { roots } = await initServer ( )
308304 bindShortcut ( )
309305
310306 // Start watcher to restart server on file changes
311307 const { watch } = await import ( 'chokidar' )
312- const watcher = watch ( [
313- ... FILES_CREATE_RESTART ,
314- ... FILES_CHANGE_RESTART ,
315- ] , {
308+ const watchGlobs = roots
309+ . filter ( i => ! i . includes ( 'node_modules' ) )
310+ . flatMap ( root => FILES_CHANGE_RESTART . map ( i => path . join ( root , i ) ) )
311+ const watcher = watch ( watchGlobs , {
316312 ignored : [ 'node_modules' , '.git' ] ,
317313 ignoreInitial : true ,
314+ ignorePermissionErrors : true ,
318315 } )
319316 watcher . on ( 'unlink' , ( file ) => {
320317 console . log ( yellow ( `\n file ${ file } removed, restarting...\n` ) )
@@ -325,10 +322,6 @@ cli.command(
325322 restartServer ( )
326323 } )
327324 watcher . on ( 'change' , ( file ) => {
328- if ( typeof file !== 'string' )
329- return
330- if ( FILES_CREATE_RESTART . includes ( file ) )
331- return
332325 console . log ( yellow ( `\n file ${ file } changed, restarting...\n` ) )
333326 restartServer ( )
334327 } )
0 commit comments