@@ -30,21 +30,12 @@ var openBrowser = require('react-dev-utils/openBrowser');
30
30
var prompt = require ( 'react-dev-utils/prompt' ) ;
31
31
var config = require ( '../config/webpack.config.dev' ) ;
32
32
var paths = require ( '../config/paths' ) ;
33
- var getCustomConfig = require ( '../config/get-custom-config' ) ;
34
- var customConfig = getCustomConfig ( false ) ;
35
33
36
34
// Warn and crash if required files are missing
37
35
if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
38
36
process . exit ( 1 ) ;
39
37
}
40
38
41
- function log ( ) {
42
- if ( customConfig . values . WEBPACK_DASHBOARD === true ) {
43
- return ;
44
- }
45
- console . log . apply ( null , arguments ) ;
46
- } ;
47
-
48
39
// Tools like Cloud9 rely on this.
49
40
var DEFAULT_PORT = process . env . PORT || 3000 ;
50
41
var compiler ;
@@ -72,73 +63,73 @@ function setupCompiler(host, port, protocol) {
72
63
// recompiling a bundle. WebpackDevServer takes care to pause serving the
73
64
// bundle, so if you refresh, it'll wait instead of serving the old one.
74
65
// "invalid" is short for "bundle invalidated", it doesn't imply any errors.
75
- compiler . plugin ( 'invalid' , function ( ) {
66
+ compiler . plugin ( 'invalid' , function ( ) {
76
67
clearConsole ( ) ;
77
- log ( 'Compiling...' ) ;
68
+ console . log ( 'Compiling...' ) ;
78
69
} ) ;
79
70
80
71
// "done" event fires when Webpack has finished recompiling the bundle.
81
72
// Whether or not you have warnings or errors, you will get this event.
82
- compiler . plugin ( 'done' , function ( stats ) {
73
+ compiler . plugin ( 'done' , function ( stats ) {
83
74
clearConsole ( ) ;
84
75
85
76
// We have switched off the default Webpack output in WebpackDevServer
86
77
// options so we are going to "massage" the warnings and errors and present
87
78
// them in a readable focused way.
88
79
var messages = formatWebpackMessages ( stats . toJson ( { } , true ) ) ;
89
80
if ( ! messages . errors . length && ! messages . warnings . length ) {
90
- log ( chalk . green ( 'Compiled successfully!' ) ) ;
91
- log ( ) ;
92
- log ( 'The app is running at:' ) ;
93
- log ( ) ;
94
- log ( ' ' + chalk . cyan ( protocol + '://' + host + ':' + port + '/' ) ) ;
95
- log ( ) ;
96
- log ( 'Note that the development build is not optimized.' ) ;
97
- log ( 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.' ) ;
98
- log ( ) ;
81
+ console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
82
+ console . log ( ) ;
83
+ console . log ( 'The app is running at:' ) ;
84
+ console . log ( ) ;
85
+ console . log ( ' ' + chalk . cyan ( protocol + '://' + host + ':' + port + '/' ) ) ;
86
+ console . log ( ) ;
87
+ console . log ( 'Note that the development build is not optimized.' ) ;
88
+ console . log ( 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.' ) ;
89
+ console . log ( ) ;
99
90
}
100
91
101
92
// If errors exist, only show errors.
102
93
if ( messages . errors . length ) {
103
- log ( chalk . red ( 'Failed to compile.' ) ) ;
104
- log ( ) ;
94
+ console . log ( chalk . red ( 'Failed to compile.' ) ) ;
95
+ console . log ( ) ;
105
96
messages . errors . forEach ( message => {
106
- log ( message ) ;
107
- log ( ) ;
97
+ console . log ( message ) ;
98
+ console . log ( ) ;
108
99
} ) ;
109
100
return ;
110
101
}
111
102
112
103
// Show warnings if no errors were found.
113
104
if ( messages . warnings . length ) {
114
- log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
115
- log ( ) ;
105
+ console . log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
106
+ console . log ( ) ;
116
107
messages . warnings . forEach ( message => {
117
- log ( message ) ;
118
- log ( ) ;
108
+ console . log ( message ) ;
109
+ console . log ( ) ;
119
110
} ) ;
120
111
// Teach some ESLint tricks.
121
- log ( 'You may use special comments to disable some warnings.' ) ;
122
- log ( 'Use ' + chalk . yellow ( '// eslint-disable-next-line' ) + ' to ignore the next line.' ) ;
123
- log ( 'Use ' + chalk . yellow ( '/* eslint-disable */' ) + ' to ignore all warnings in a file.' ) ;
112
+ console . log ( 'You may use special comments to disable some warnings.' ) ;
113
+ console . log ( 'Use ' + chalk . yellow ( '// eslint-disable-next-line' ) + ' to ignore the next line.' ) ;
114
+ console . log ( 'Use ' + chalk . yellow ( '/* eslint-disable */' ) + ' to ignore all warnings in a file.' ) ;
124
115
}
125
116
} ) ;
126
117
}
127
118
128
119
// We need to provide a custom onError function for httpProxyMiddleware.
129
120
// It allows us to log custom error messages on the console.
130
121
function onProxyError ( proxy ) {
131
- return function ( err , req , res ) {
122
+ return function ( err , req , res ) {
132
123
var host = req . headers && req . headers . host ;
133
- log (
124
+ console . log (
134
125
chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
135
126
' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
136
127
) ;
137
- log (
128
+ console . log (
138
129
'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
139
130
chalk . cyan ( err . code ) + ').'
140
131
) ;
141
- log ( ) ;
132
+ console . log ( ) ;
142
133
143
134
// And immediately send the proper error response to the client.
144
135
// Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
@@ -172,9 +163,9 @@ function addMiddleware(devServer) {
172
163
} ) ) ;
173
164
if ( proxy ) {
174
165
if ( typeof proxy !== 'string' ) {
175
- log ( chalk . red ( 'When specified, "proxy" in package.json must be a string.' ) ) ;
176
- log ( chalk . red ( 'Instead, the type of "proxy" was "' + typeof proxy + '".' ) ) ;
177
- log ( chalk . red ( 'Either remove "proxy" from package.json, or make it a string.' ) ) ;
166
+ console . log ( chalk . red ( 'When specified, "proxy" in package.json must be a string.' ) ) ;
167
+ console . log ( chalk . red ( 'Instead, the type of "proxy" was "' + typeof proxy + '".' ) ) ;
168
+ console . log ( chalk . red ( 'Either remove "proxy" from package.json, or make it a string.' ) ) ;
178
169
process . exit ( 1 ) ;
179
170
}
180
171
@@ -183,7 +174,7 @@ function addMiddleware(devServer) {
183
174
// - /index.html (served as HTML5 history API fallback)
184
175
// - /*.hot-update.json (WebpackDevServer uses this too for hot reloading)
185
176
// - /sockjs-node/* (WebpackDevServer uses this for hot reloading)
186
- // Tip: use https://www.debuggex.com / to visualize the regex
177
+ // Tip: use https://jex.im/regulex / to visualize the regex
187
178
var mayProxy = / ^ (? ! \/ ( i n d e x \. h t m l $ | .* \. h o t - u p d a t e \. j s o n $ | s o c k j s - n o d e \/ ) ) .* $ / ;
188
179
devServer . use ( mayProxy ,
189
180
// Pass the scope regex both to Express and to the middleware for proxying
@@ -250,12 +241,12 @@ function runDevServer(host, port, protocol) {
250
241
// Launch WebpackDevServer.
251
242
devServer . listen ( port , ( err , result ) => {
252
243
if ( err ) {
253
- return log ( err ) ;
244
+ return console . log ( err ) ;
254
245
}
255
246
256
- log ( chalk . cyan ( 'Starting the development server...' ) ) ;
257
- log ( ) ;
258
-
247
+ clearConsole ( ) ;
248
+ console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
249
+ console . log ( ) ;
259
250
if ( process . env && process . env . OPEN_BROWSER !== 'false' ) {
260
251
openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
261
252
}
@@ -272,11 +263,12 @@ function run(port) {
272
263
// We attempt to use the default port but if it is busy, we offer the user to
273
264
// run on a different port. `detect()` Promise resolves to the next free port.
274
265
detect ( DEFAULT_PORT ) . then ( port => {
275
- if ( port === DEFAULT_PORT || customConfig . values . WEBPACK_DASHBOARD === true ) {
266
+ if ( port === DEFAULT_PORT ) {
276
267
run ( port ) ;
277
268
return ;
278
269
}
279
270
271
+ clearConsole ( ) ;
280
272
var question =
281
273
chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) +
282
274
'\n\nWould you like to run the app on another port instead?' ;
0 commit comments