@@ -30,21 +30,12 @@ var openBrowser = require('react-dev-utils/openBrowser');
3030var prompt = require ( 'react-dev-utils/prompt' ) ;
3131var config = require ( '../config/webpack.config.dev' ) ;
3232var paths = require ( '../config/paths' ) ;
33- var getCustomConfig = require ( '../config/get-custom-config' ) ;
34- var customConfig = getCustomConfig ( false ) ;
3533
3634// Warn and crash if required files are missing
3735if ( ! checkRequiredFiles ( [ paths . appHtml , paths . appIndexJs ] ) ) {
3836 process . exit ( 1 ) ;
3937}
4038
41- function log ( ) {
42- if ( customConfig . values . WEBPACK_DASHBOARD === true ) {
43- return ;
44- }
45- console . log . apply ( null , arguments ) ;
46- } ;
47-
4839// Tools like Cloud9 rely on this.
4940var DEFAULT_PORT = process . env . PORT || 3000 ;
5041var compiler ;
@@ -72,73 +63,73 @@ function setupCompiler(host, port, protocol) {
7263 // recompiling a bundle. WebpackDevServer takes care to pause serving the
7364 // bundle, so if you refresh, it'll wait instead of serving the old one.
7465 // "invalid" is short for "bundle invalidated", it doesn't imply any errors.
75- compiler . plugin ( 'invalid' , function ( ) {
66+ compiler . plugin ( 'invalid' , function ( ) {
7667 clearConsole ( ) ;
77- log ( 'Compiling...' ) ;
68+ console . log ( 'Compiling...' ) ;
7869 } ) ;
7970
8071 // "done" event fires when Webpack has finished recompiling the bundle.
8172 // 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 ) {
8374 clearConsole ( ) ;
8475
8576 // We have switched off the default Webpack output in WebpackDevServer
8677 // options so we are going to "massage" the warnings and errors and present
8778 // them in a readable focused way.
8879 var messages = formatWebpackMessages ( stats . toJson ( { } , true ) ) ;
8980 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 ( ) ;
9990 }
10091
10192 // If errors exist, only show errors.
10293 if ( messages . errors . length ) {
103- log ( chalk . red ( 'Failed to compile.' ) ) ;
104- log ( ) ;
94+ console . log ( chalk . red ( 'Failed to compile.' ) ) ;
95+ console . log ( ) ;
10596 messages . errors . forEach ( message => {
106- log ( message ) ;
107- log ( ) ;
97+ console . log ( message ) ;
98+ console . log ( ) ;
10899 } ) ;
109100 return ;
110101 }
111102
112103 // Show warnings if no errors were found.
113104 if ( messages . warnings . length ) {
114- log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
115- log ( ) ;
105+ console . log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
106+ console . log ( ) ;
116107 messages . warnings . forEach ( message => {
117- log ( message ) ;
118- log ( ) ;
108+ console . log ( message ) ;
109+ console . log ( ) ;
119110 } ) ;
120111 // 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.' ) ;
124115 }
125116 } ) ;
126117}
127118
128119// We need to provide a custom onError function for httpProxyMiddleware.
129120// It allows us to log custom error messages on the console.
130121function onProxyError ( proxy ) {
131- return function ( err , req , res ) {
122+ return function ( err , req , res ) {
132123 var host = req . headers && req . headers . host ;
133- log (
124+ console . log (
134125 chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
135126 ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
136127 ) ;
137- log (
128+ console . log (
138129 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
139130 chalk . cyan ( err . code ) + ').'
140131 ) ;
141- log ( ) ;
132+ console . log ( ) ;
142133
143134 // And immediately send the proper error response to the client.
144135 // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
@@ -172,9 +163,9 @@ function addMiddleware(devServer) {
172163 } ) ) ;
173164 if ( proxy ) {
174165 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.' ) ) ;
178169 process . exit ( 1 ) ;
179170 }
180171
@@ -183,7 +174,7 @@ function addMiddleware(devServer) {
183174 // - /index.html (served as HTML5 history API fallback)
184175 // - /*.hot-update.json (WebpackDevServer uses this too for hot reloading)
185176 // - /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
187178 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 \/ ) ) .* $ / ;
188179 devServer . use ( mayProxy ,
189180 // Pass the scope regex both to Express and to the middleware for proxying
@@ -250,12 +241,12 @@ function runDevServer(host, port, protocol) {
250241 // Launch WebpackDevServer.
251242 devServer . listen ( port , ( err , result ) => {
252243 if ( err ) {
253- return log ( err ) ;
244+ return console . log ( err ) ;
254245 }
255246
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 ( ) ;
259250 if ( process . env && process . env . OPEN_BROWSER !== 'false' ) {
260251 openBrowser ( protocol + '://' + host + ':' + port + '/' ) ;
261252 }
@@ -272,11 +263,12 @@ function run(port) {
272263// We attempt to use the default port but if it is busy, we offer the user to
273264// run on a different port. `detect()` Promise resolves to the next free port.
274265detect ( DEFAULT_PORT ) . then ( port => {
275- if ( port === DEFAULT_PORT || customConfig . values . WEBPACK_DASHBOARD === true ) {
266+ if ( port === DEFAULT_PORT ) {
276267 run ( port ) ;
277268 return ;
278269 }
279270
271+ clearConsole ( ) ;
280272 var question =
281273 chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) +
282274 '\n\nWould you like to run the app on another port instead?' ;
0 commit comments