@@ -67,7 +67,7 @@ function setupCompiler(port, protocol) {
6767
6868 // "done" event fires when Webpack has finished recompiling the bundle.
6969 // Whether or not you have warnings or errors, you will get this event.
70- compiler . plugin ( 'done' , ( stats ) => {
70+ compiler . plugin ( 'done' , stats => {
7171 clearConsole ( ) ;
7272 const hasErrors = stats . hasErrors ( ) ;
7373 const hasWarnings = stats . hasWarnings ( ) ;
@@ -79,7 +79,9 @@ function setupCompiler(port, protocol) {
7979 console . log ( ' ' + chalk . cyan ( protocol + '://localhost:' + port + '/' ) ) ;
8080 console . log ( ) ;
8181 console . log ( 'Note that the development build is not optimized.' ) ;
82- console . log ( 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.' ) ;
82+ console . log (
83+ 'To create a production build, use ' + chalk . cyan ( 'npm run build' ) + '.'
84+ ) ;
8385 console . log ( ) ;
8486 return ;
8587 }
@@ -90,11 +92,11 @@ function setupCompiler(port, protocol) {
9092 // We use stats.toJson({}, true) to make output more compact and readable:
9193 // https://github.com/facebookincubator/create-react-app/issues/401#issuecomment-238291901
9294 var json = stats . toJson ( { } , true ) ;
93- var formattedErrors = json . errors . map ( message =>
94- 'Error in ' + formatMessage ( message )
95+ var formattedErrors = json . errors . map (
96+ message => 'Error in ' + formatMessage ( message )
9597 ) ;
96- var formattedWarnings = json . warnings . map ( message =>
97- 'Warning in ' + formatMessage ( message )
98+ var formattedWarnings = json . warnings . map (
99+ message => 'Warning in ' + formatMessage ( message )
98100 ) ;
99101 if ( hasErrors ) {
100102 console . log ( chalk . red ( 'Failed to compile.' ) ) ;
@@ -121,8 +123,16 @@ function setupCompiler(port, protocol) {
121123 } ) ;
122124 // Teach some ESLint tricks.
123125 console . log ( 'You may use special comments to disable some warnings.' ) ;
124- console . log ( 'Use ' + chalk . yellow ( '// eslint-disable-next-line' ) + ' to ignore the next line.' ) ;
125- console . log ( 'Use ' + chalk . yellow ( '/* eslint-disable */' ) + ' to ignore all warnings in a file.' ) ;
126+ console . log (
127+ 'Use ' +
128+ chalk . yellow ( '// eslint-disable-next-line' ) +
129+ ' to ignore the next line.'
130+ ) ;
131+ console . log (
132+ 'Use ' +
133+ chalk . yellow ( '/* eslint-disable */' ) +
134+ ' to ignore all warnings in a file.'
135+ ) ;
126136 }
127137 } ) ;
128138}
@@ -134,8 +144,12 @@ function openBrowser(port, protocol) {
134144 // on OS X Google Chrome with AppleScript
135145 execSync ( 'ps cax | grep "Google Chrome"' ) ;
136146 execSync (
137- 'osascript chrome.applescript ' + protocol + '://localhost:' + port + '/' ,
138- { cwd : path . join ( __dirname , 'utils' ) , stdio : 'ignore' }
147+ 'osascript chrome.applescript ' +
148+ protocol +
149+ '://localhost:' +
150+ port +
151+ '/' ,
152+ { cwd : path . join ( __dirname , 'utils' ) , stdio : 'ignore' }
139153 ) ;
140154 return ;
141155 } catch ( err ) {
@@ -150,43 +164,59 @@ function openBrowser(port, protocol) {
150164// We need to provide a custom onError function for httpProxyMiddleware.
151165// It allows us to log custom error messages on the console.
152166function onProxyError ( proxy ) {
153- return function ( err , req , res ) {
167+ return function ( err , req , res ) {
154168 var host = req . headers && req . headers . host ;
155169 console . log (
156- chalk . red ( 'Proxy error:' ) + ' Could not proxy request ' + chalk . cyan ( req . url ) +
157- ' from ' + chalk . cyan ( host ) + ' to ' + chalk . cyan ( proxy ) + '.'
170+ chalk . red ( 'Proxy error:' ) +
171+ ' Could not proxy request ' +
172+ chalk . cyan ( req . url ) +
173+ ' from ' +
174+ chalk . cyan ( host ) +
175+ ' to ' +
176+ chalk . cyan ( proxy ) +
177+ '.'
158178 ) ;
159179 console . log (
160180 'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
161- chalk . cyan ( err . code ) + ').'
181+ chalk . cyan ( err . code ) +
182+ ').'
162183 ) ;
163184 console . log ( ) ;
164- }
185+ } ;
165186}
166187
167188function addMiddleware ( devServer ) {
168189 // `proxy` lets you to specify a fallback server during development.
169190 // Every unrecognized request will be forwarded to it.
170191 var proxy = require ( paths . appPackageJson ) . proxy ;
171- devServer . use ( historyApiFallback ( {
172- // Allow paths with dots in them to be loaded, reference issue #387
173- disableDotRule : true ,
174- // For single page apps, we generally want to fallback to /index.html.
175- // However we also want to respect `proxy` for API calls.
176- // So if `proxy` is specified, we need to decide which fallback to use.
177- // We use a heuristic: if request `accept`s text/html, we pick /index.html.
178- // Modern browsers include text/html into `accept` header when navigating.
179- // However API calls like `fetch()` won’t generally won’t accept text/html.
180- // If this heuristic doesn’t work well for you, don’t use `proxy`.
181- htmlAcceptHeaders : proxy ?
182- [ 'text/html' ] :
183- [ 'text/html' , '*/*' ]
184- } ) ) ;
192+ devServer . use (
193+ historyApiFallback ( {
194+ // Allow paths with dots in them to be loaded, reference issue #387
195+ disableDotRule : true ,
196+ // For single page apps, we generally want to fallback to /index.html.
197+ // However we also want to respect `proxy` for API calls.
198+ // So if `proxy` is specified, we need to decide which fallback to use.
199+ // We use a heuristic: if request `accept`s text/html, we pick /index.html.
200+ // Modern browsers include text/html into `accept` header when navigating.
201+ // However API calls like `fetch()` won’t generally won’t accept text/html.
202+ // If this heuristic doesn’t work well for you, don’t use `proxy`.
203+ htmlAcceptHeaders : proxy ? [ 'text/html' ] : [ 'text/html' , '*/*' ] ,
204+ index : '/app.html' ,
205+ } )
206+ ) ;
185207 if ( proxy ) {
186208 if ( typeof proxy !== 'string' ) {
187- console . log ( chalk . red ( 'When specified, "proxy" in package.json must be a string.' ) ) ;
188- console . log ( chalk . red ( 'Instead, the type of "proxy" was "' + typeof proxy + '".' ) ) ;
189- console . log ( chalk . red ( 'Either remove "proxy" from package.json, or make it a string.' ) ) ;
209+ console . log (
210+ chalk . red ( 'When specified, "proxy" in package.json must be a string.' )
211+ ) ;
212+ console . log (
213+ chalk . red ( 'Instead, the type of "proxy" was "' + typeof proxy + '".' )
214+ ) ;
215+ console . log (
216+ chalk . red (
217+ 'Either remove "proxy" from package.json, or make it a string.'
218+ )
219+ ) ;
190220 process . exit ( 1 ) ;
191221 }
192222
@@ -197,15 +227,16 @@ function addMiddleware(devServer) {
197227 // - /sockjs-node/* (WebpackDevServer uses this for hot reloading)
198228 // Tip: use https://www.debuggex.com/ to visualize the regex
199229 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 \/ ) ) .* $ / ;
200- devServer . use ( mayProxy ,
230+ devServer . use (
231+ mayProxy ,
201232 // Pass the scope regex both to Express and to the middleware for proxying
202233 // of both HTTP and WebSockets to work without false positives.
203234 httpProxyMiddleware ( pathname => mayProxy . test ( pathname ) , {
204235 target : proxy ,
205236 logLevel : 'silent' ,
206237 onError : onProxyError ( proxy ) ,
207238 secure : false ,
208- changeOrigin : true
239+ changeOrigin : true ,
209240 } )
210241 ) ;
211242 }
@@ -235,6 +266,7 @@ function runDevServer(port, protocol) {
235266 } ,
236267 // Enable HTTPS if the HTTPS environment variable is set to 'true'
237268 https : protocol === 'https' ,
269+ // contentBase: paths.staticPath,
238270 } ) ;
239271
240272 // Our custom middleware proxies requests to /index.html or a remote API.
@@ -254,7 +286,7 @@ function runDevServer(port, protocol) {
254286}
255287
256288function run ( port ) {
257- var protocol = process . env . HTTPS === 'true' ? " https" : " http" ;
289+ var protocol = process . env . HTTPS === 'true' ? ' https' : ' http' ;
258290 setupCompiler ( port , protocol ) ;
259291 runDevServer ( port , protocol ) ;
260292}
@@ -268,9 +300,9 @@ detect(DEFAULT_PORT).then(port => {
268300 }
269301
270302 clearConsole ( ) ;
271- var question =
272- chalk . yellow ( 'Something is already running on port ' + DEFAULT_PORT + '.' ) +
273- '\n\nWould you like to run the app on another port instead?' ;
303+ var question = chalk . yellow (
304+ 'Something is already running on port ' + DEFAULT_PORT + '.'
305+ ) + '\n\nWould you like to run the app on another port instead?' ;
274306
275307 prompt ( question , true ) . then ( shouldChangePort => {
276308 if ( shouldChangePort ) {
0 commit comments