1111
1212process . env . NODE_ENV = 'development' ;
1313
14+ var fs = require ( 'fs' ) ;
1415var path = require ( 'path' ) ;
1516var chalk = require ( 'chalk' ) ;
1617var webpack = require ( 'webpack' ) ;
@@ -170,6 +171,20 @@ function openBrowser(port, protocol) {
170171 opn ( protocol + '://localhost:' + port + '/' ) ;
171172}
172173
174+ function checkRequiredFiles ( ) {
175+ var filesPathToCheck = [ paths . appHtml , paths . appIndexJs ] ;
176+ filesPathToCheck . forEach ( function ( filePath ) {
177+ try {
178+ fs . accessSync ( filePath , fs . F_OK ) ;
179+ } catch ( err ) {
180+ var fileName = path . basename ( filePath ) ;
181+ console . log (
182+ chalk . red ( `Cannot find ${ fileName } in ${ filePath } directory` )
183+ ) ;
184+ process . exit ( 1 ) ;
185+ }
186+ } ) ;
187+ }
173188// We need to provide a custom onError function for httpProxyMiddleware.
174189// It allows us to log custom error messages on the console.
175190function onProxyError ( proxy ) {
@@ -180,7 +195,7 @@ function onProxyError(proxy) {
180195 ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
181196 ) ;
182197 console . log (
183- 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
198+ 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
184199 chalk . cyan ( err . code ) + ').'
185200 ) ;
186201 console . log ( ) ;
@@ -190,7 +205,7 @@ function onProxyError(proxy) {
190205 if ( res . writeHead && ! res . headersSent ) {
191206 res . writeHead ( 500 ) ;
192207 }
193- res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
208+ res . end ( 'Proxy error: Could not proxy request ' + req . url + ' from ' +
194209 host + ' to ' + proxy + ' (' + err . code + ').'
195210 ) ;
196211 }
@@ -304,6 +319,7 @@ function runDevServer(port, protocol) {
304319
305320function run ( port ) {
306321 var protocol = process . env . HTTPS === 'true' ? "https" : "http" ;
322+ checkRequiredFiles ( ) ;
307323 setupCompiler ( port , protocol ) ;
308324 runDevServer ( port , protocol ) ;
309325}
0 commit comments