@@ -94,6 +94,51 @@ function setupCompiler(port) {
94
94
var hasWarnings = stats . hasWarnings ( ) ;
95
95
if ( ! hasErrors && ! hasWarnings ) {
96
96
console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
97
+ }
98
+ else {
99
+ // We have switched off the default Webpack output in WebpackDevServer
100
+ // options so we are going to "massage" the warnings and errors and present
101
+ // them in a readable focused way.
102
+ // We use stats.toJson({}, true) to make output more compact and readable:
103
+ // https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
104
+ var json = stats . toJson ( { } , true ) ;
105
+ var formattedErrors = json . errors . map ( message =>
106
+ 'Error in ' + formatMessage ( message )
107
+ ) ;
108
+ var formattedWarnings = json . warnings . map ( message =>
109
+ 'Warning in ' + formatMessage ( message )
110
+ ) ;
111
+ if ( hasErrors ) {
112
+ console . log ( chalk . red ( 'Failed to compile.' ) ) ;
113
+ console . log ( ) ;
114
+ if ( formattedErrors . some ( isLikelyASyntaxError ) ) {
115
+ // If there are any syntax errors, show just them.
116
+ // This prevents a confusing ESLint parsing error
117
+ // preceding a much more useful Babel syntax error.
118
+ formattedErrors = formattedErrors . filter ( isLikelyASyntaxError ) ;
119
+ }
120
+ formattedErrors . forEach ( message => {
121
+ console . log ( message ) ;
122
+ console . log ( ) ;
123
+ } ) ;
124
+ // If errors exist, ignore warnings.
125
+ return ;
126
+ }
127
+ if ( hasWarnings ) {
128
+ console . log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
129
+ console . log ( ) ;
130
+ formattedWarnings . forEach ( message => {
131
+ console . log ( message ) ;
132
+ console . log ( ) ;
133
+ } ) ;
134
+ // Teach some ESLint tricks.
135
+ console . log ( 'You may use special comments to disable some warnings.' ) ;
136
+ console . log ( 'Use ' + chalk . yellow ( '// eslint-disable-next-line' ) + ' to ignore the next line.' ) ;
137
+ console . log ( 'Use ' + chalk . yellow ( '/* eslint-disable */' ) + ' to ignore all warnings in a file.' ) ;
138
+ }
139
+ }
140
+
141
+ if ( ! hasErrors ) {
97
142
console . log ( ) ;
98
143
console . log ( 'The app is running at:' ) ;
99
144
console . log ( ) ;
@@ -102,48 +147,6 @@ function setupCompiler(port) {
102
147
console . log ( 'Note that the development build is not optimized.' ) ;
103
148
console . log ( 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.' ) ;
104
149
console . log ( ) ;
105
- return ;
106
- }
107
-
108
- // We have switched off the default Webpack output in WebpackDevServer
109
- // options so we are going to "massage" the warnings and errors and present
110
- // them in a readable focused way.
111
- // We use stats.toJson({}, true) to make output more compact and readable:
112
- // https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
113
- var json = stats . toJson ( { } , true ) ;
114
- var formattedErrors = json . errors . map ( message =>
115
- 'Error in ' + formatMessage ( message )
116
- ) ;
117
- var formattedWarnings = json . warnings . map ( message =>
118
- 'Warning in ' + formatMessage ( message )
119
- ) ;
120
- if ( hasErrors ) {
121
- console . log ( chalk . red ( 'Failed to compile.' ) ) ;
122
- console . log ( ) ;
123
- if ( formattedErrors . some ( isLikelyASyntaxError ) ) {
124
- // If there are any syntax errors, show just them.
125
- // This prevents a confusing ESLint parsing error
126
- // preceding a much more useful Babel syntax error.
127
- formattedErrors = formattedErrors . filter ( isLikelyASyntaxError ) ;
128
- }
129
- formattedErrors . forEach ( message => {
130
- console . log ( message ) ;
131
- console . log ( ) ;
132
- } ) ;
133
- // If errors exist, ignore warnings.
134
- return ;
135
- }
136
- if ( hasWarnings ) {
137
- console . log ( chalk . yellow ( 'Compiled with warnings.' ) ) ;
138
- console . log ( ) ;
139
- formattedWarnings . forEach ( message => {
140
- console . log ( message ) ;
141
- console . log ( ) ;
142
- } ) ;
143
- // Teach some ESLint tricks.
144
- console . log ( 'You may use special comments to disable some warnings.' ) ;
145
- console . log ( 'Use ' + chalk . yellow ( '// eslint-disable-next-line' ) + ' to ignore the next line.' ) ;
146
- console . log ( 'Use ' + chalk . yellow ( '/* eslint-disable */' ) + ' to ignore all warnings in a file.' ) ;
147
150
}
148
151
} ) ;
149
152
}
0 commit comments