@@ -56,6 +56,10 @@ async function createViteDevServer() {
5656
5757 return createServer ( {
5858 configFile : normalizePath ( "vite.config.ts" ) ,
59+ optimizeDeps : {
60+ noDiscovery : true ,
61+ include : [ ]
62+ } ,
5963 server : {
6064 middlewareMode : true ,
6165 hmr : false ,
@@ -84,10 +88,16 @@ async function runViteController(rawArgs: string[]) {
8488 const watch = parseWatchValue ( rawArgs ) ;
8589 const vite = await createViteDevServer ( ) ;
8690 let childProcess : ReturnType < typeof spawn > | undefined ;
91+ let childStarted = false ;
8792 let restarting = false ;
8893 let queued = false ;
8994
9095 const startChild = ( ) => {
96+ if ( childStarted ) {
97+ return ;
98+ }
99+
100+ childStarted = true ;
91101 const cliEntry = process . argv [ 1 ] ;
92102
93103 childProcess = spawn ( process . execPath , cliEntry ? [ cliEntry , "dev" , ...rawArgs ] : [ runnerFile , ...rawArgs ] , {
@@ -97,17 +107,26 @@ async function runViteController(rawArgs: string[]) {
97107 } ,
98108 stdio : "inherit"
99109 } ) ;
110+
111+ childProcess . once ( "exit" , ( ) => {
112+ childStarted = false ;
113+ childProcess = undefined ;
114+ } ) ;
100115 } ;
101116
102117 const stopChild = async ( ) => {
103- if ( ! childProcess || childProcess . killed ) {
118+ if ( ! childProcess || childProcess . killed || childProcess . exitCode !== null || childProcess . signalCode !== null ) {
119+ childStarted = false ;
120+ childProcess = undefined ;
104121 return ;
105122 }
106123
107124 await new Promise ( ( resolve ) => {
108125 childProcess ! . once ( "exit" , resolve ) ;
109126 childProcess ! . kill ( "SIGTERM" ) ;
110127 } ) ;
128+
129+ childStarted = false ;
111130 } ;
112131
113132 const restartChild = async ( reason : string , file = "" ) => {
@@ -143,9 +162,7 @@ async function runViteController(rawArgs: string[]) {
143162 } ) ;
144163 }
145164
146- vite . watcher . once ( "ready" , ( ) => {
147- startChild ( ) ;
148- } ) ;
165+ startChild ( ) ;
149166
150167 const shutdown = async ( ) => {
151168 await stopChild ( ) ;
0 commit comments