@@ -29,12 +29,22 @@ const workbox = require('workbox-build');
2929const { File, FileReader } = require ( 'file-api' ) ;
3030const handlebars = require ( 'handlebars' ) ;
3131const { resolve } = require ( 'path' ) ;
32+ const axios = require ( 'axios' ) ;
33+ const axiosRetry = require ( 'axios-retry' ) ;
3234
3335// For backward compatibility with gulp override tasks using run-sequence module
3436// make compatible with gulp4
3537require ( 'module-alias' ) . addAlias ( 'run-sequence' , 'gulp4-run-sequence' ) ;
3638
3739const reactium = ( gulp , config , webpackConfig ) => {
40+ axiosRetry ( axios , {
41+ retries : config . serverRetries ,
42+ retryDelay : retryCount => {
43+ console . log ( `retry attempt: ${ retryCount } ` ) ;
44+ return retryCount * config . serverRetryDelay ; // time interval between retries
45+ } ,
46+ } ) ;
47+
3848 const task = require ( './get-task' ) ( gulp ) ;
3949
4050 const env = process . env . NODE_ENV || 'development' ;
@@ -109,23 +119,21 @@ const reactium = (gulp, config, webpackConfig) => {
109119
110120 const serve = ( { open } = { open : config . open } ) => done => {
111121 const proxy = `localhost:${ config . port . proxy } ` ;
112- require ( 'axios' )
113- . get ( `http://${ proxy } ` )
114- . then ( ( ) => {
115- browserSync ( {
116- notify : false ,
117- timestamps : false ,
118- port : config . port . browsersync ,
119- ui : { port : config . port . browsersync + 1 } ,
120- proxy,
121- open : open ,
122- ghostMode : false ,
123- startPath : config . dest . startPath ,
124- ws : true ,
125- } ) ;
126-
127- done ( ) ;
122+ axios . get ( `http://${ proxy } ` ) . then ( ( ) => {
123+ browserSync ( {
124+ notify : false ,
125+ timestamps : false ,
126+ port : config . port . browsersync ,
127+ ui : { port : config . port . browsersync + 1 } ,
128+ proxy,
129+ open : open ,
130+ ghostMode : false ,
131+ startPath : config . dest . startPath ,
132+ ws : true ,
128133 } ) ;
134+
135+ done ( ) ;
136+ } ) ;
129137 } ;
130138
131139 const watch = ( done , restart = false ) => {
@@ -142,9 +150,20 @@ const reactium = (gulp, config, webpackConfig) => {
142150 return ;
143151 }
144152 case 'restart-watches' : {
145- console . log ( "Restarting 'watch'..." ) ;
146- watchProcess . kill ( ) ;
147- watch ( _ => _ , true ) ;
153+ console . log ( 'Waiting for server...' ) ;
154+ new Promise ( resolve =>
155+ setTimeout ( resolve , config . serverRetryDelay ) ,
156+ )
157+ . then ( ( ) => {
158+ const proxy = `localhost:${ config . port . proxy } ` ;
159+ return axios . get ( `http://${ proxy } ` ) ;
160+ } )
161+ . then ( ( ) => {
162+ console . log ( "Restarting 'watch'..." ) ;
163+ watchProcess . kill ( ) ;
164+ watch ( _ => _ , true ) ;
165+ } )
166+ . catch ( error => console . error ( error ) ) ;
148167 return ;
149168 }
150169 }
0 commit comments