@@ -35,6 +35,7 @@ var paths = require('../config/paths');
35
35
36
36
var useYarn = pathExists . sync ( paths . yarnLockFile ) ;
37
37
var cli = useYarn ? 'yarn' : 'npm' ;
38
+ var isInteractive = process . stdout . isTTY ;
38
39
39
40
// Warn and crash if required files are missing
40
41
if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
@@ -71,21 +72,33 @@ function setupCompiler(host, port, protocol) {
71
72
// bundle, so if you refresh, it'll wait instead of serving the old one.
72
73
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
73
74
compiler . plugin ( 'invalid' , function ( ) {
74
- clearConsole ( ) ;
75
+ if ( isInteractive ) {
76
+ clearConsole ( ) ;
77
+ }
75
78
console . log ( 'Compiling...' ) ;
76
79
} ) ;
77
80
81
+ var isFirstCompile = true ;
82
+
78
83
// "done" event fires when Webpack has finished recompiling the bundle.
79
84
// Whether or not you have warnings or errors, you will get this event.
80
85
compiler . plugin ( 'done' , function ( stats ) {
81
- clearConsole ( ) ;
86
+ if ( isInteractive ) {
87
+ clearConsole ( ) ;
88
+ }
82
89
83
90
// We have switched off the default Webpack output in WebpackDevServer
84
91
// options so we are going to "massage" the warnings and errors and present
85
92
// them in a readable focused way.
86
93
var messages = formatWebpackMessages ( stats . toJson ( { } , true ) ) ;
87
- if ( ! messages . errors . length && ! messages . warnings . length ) {
94
+ var isSuccessful = ! messages . errors . length && ! messages . warnings . length ;
95
+ var showInstructions = isSuccessful && ( isInteractive || isFirstCompile ) ;
96
+
97
+ if ( isSuccessful ) {
88
98
console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
99
+ }
100
+
101
+ if ( showInstructions ) {
89
102
console . log ( ) ;
90
103
console . log ( 'The app is running at:' ) ;
91
104
console . log ( ) ;
@@ -94,6 +107,7 @@ function setupCompiler(host, port, protocol) {
94
107
console . log ( 'Note that the development build is not optimized.' ) ;
95
108
console . log ( 'To create a production build, use ' + chalk . cyan ( cli + ' run build' ) + '.' ) ;
96
109
console . log ( ) ;
110
+ isFirstCompile = false ;
97
111
}
98
112
99
113
// If errors exist, only show errors.
@@ -262,8 +276,15 @@ function runDevServer(host, port, protocol) {
262
276
return console . log ( err ) ;
263
277
}
264
278
265
- clearConsole ( ) ;
279
+ if ( isInteractive ) {
280
+ clearConsole ( ) ;
281
+ }
266
282
console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
283
+ console . log ( ) ;
284
+
285
+ if ( isInteractive ) {
286
+ openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
287
+ }
267
288
} ) ;
268
289
}
269
290
@@ -286,16 +307,20 @@ detect(DEFAULT_PORT).then(port => {
286
307
return ;
287
308
}
288
309
289
- clearConsole ( ) ;
290
- var existingProcess = getProcessForPort ( DEFAULT_PORT ) ;
291
- var question =
292
- chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' +
293
- ( ( existingProcess ) ? ' Probably:\n ' + existingProcess : '' ) ) +
294
- '\n\nWould you like to run the app on another port instead?' ;
310
+ if ( isInteractive ) {
311
+ clearConsole ( ) ;
312
+ var existingProcess = getProcessForPort ( DEFAULT_PORT ) ;
313
+ var question =
314
+ chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' +
315
+ ( ( existingProcess ) ? ' Probably:\n ' + existingProcess : '' ) ) +
316
+ '\n\nWould you like to run the app on another port instead?' ;
295
317
296
- prompt ( question , true ) . then ( shouldChangePort => {
297
- if ( shouldChangePort ) {
298
- run ( port ) ;
299
- }
300
- } ) ;
318
+ prompt ( question , true ) . then ( shouldChangePort => {
319
+ if ( shouldChangePort ) {
320
+ run ( port ) ;
321
+ }
322
+ } ) ;
323
+ } else {
324
+ console . log ( chalk . red ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) ) ;
325
+ }
301
326
} ) ;
0 commit comments