2
2
/*global __resourceQuery __webpack_public_path__*/
3
3
4
4
var options = {
5
- path : " /__webpack_hmr" ,
5
+ path : ' /__webpack_hmr' ,
6
6
timeout : 20 * 1000 ,
7
7
overlay : true ,
8
8
reload : false ,
@@ -12,7 +12,7 @@ var options = {
12
12
autoConnect : true ,
13
13
overlayStyles : { } ,
14
14
overlayWarnings : false ,
15
- ansiColors : { }
15
+ ansiColors : { } ,
16
16
} ;
17
17
if ( __resourceQuery ) {
18
18
var querystring = require ( 'querystring' ) ;
@@ -25,8 +25,8 @@ if (typeof window === 'undefined') {
25
25
} else if ( typeof window . EventSource === 'undefined' ) {
26
26
console . warn (
27
27
"webpack-hot-middleware's client requires EventSource to work. " +
28
- " You should include a polyfill if you want to support this browser: " +
29
- " https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools"
28
+ ' You should include a polyfill if you want to support this browser: ' +
29
+ ' https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools'
30
30
) ;
31
31
} else {
32
32
if ( options . autoConnect ) {
@@ -41,7 +41,8 @@ function setOptionsAndConnect(overrides) {
41
41
}
42
42
43
43
function setOverrides ( overrides ) {
44
- if ( overrides . autoConnect ) options . autoConnect = overrides . autoConnect == 'true' ;
44
+ if ( overrides . autoConnect )
45
+ options . autoConnect = overrides . autoConnect == 'true' ;
45
46
if ( overrides . path ) options . path = overrides . path ;
46
47
if ( overrides . timeout ) options . timeout = overrides . timeout ;
47
48
if ( overrides . overlay ) options . overlay = overrides . overlay !== 'false' ;
@@ -61,8 +62,10 @@ function setOverrides(overrides) {
61
62
options . path = __webpack_public_path__ + options . path ;
62
63
}
63
64
64
- if ( overrides . ansiColors ) options . ansiColors = JSON . parse ( overrides . ansiColors ) ;
65
- if ( overrides . overlayStyles ) options . overlayStyles = JSON . parse ( overrides . overlayStyles ) ;
65
+ if ( overrides . ansiColors )
66
+ options . ansiColors = JSON . parse ( overrides . ansiColors ) ;
67
+ if ( overrides . overlayStyles )
68
+ options . overlayStyles = JSON . parse ( overrides . overlayStyles ) ;
66
69
67
70
if ( overrides . overlayWarnings ) {
68
71
options . overlayWarnings = overrides . overlayWarnings == 'true' ;
@@ -76,7 +79,7 @@ function EventSourceWrapper() {
76
79
77
80
init ( ) ;
78
81
var timer = setInterval ( function ( ) {
79
- if ( ( new Date ( ) - lastActivity ) > options . timeout ) {
82
+ if ( new Date ( ) - lastActivity > options . timeout ) {
80
83
handleDisconnect ( ) ;
81
84
}
82
85
} , options . timeout / 2 ) ;
@@ -89,7 +92,7 @@ function EventSourceWrapper() {
89
92
}
90
93
91
94
function handleOnline ( ) {
92
- if ( options . log ) console . log ( " [HMR] connected" ) ;
95
+ if ( options . log ) console . log ( ' [HMR] connected' ) ;
93
96
lastActivity = new Date ( ) ;
94
97
}
95
98
@@ -109,7 +112,7 @@ function EventSourceWrapper() {
109
112
return {
110
113
addMessageListener : function ( fn ) {
111
114
listeners . push ( fn ) ;
112
- }
115
+ } ,
113
116
} ;
114
117
}
115
118
@@ -129,14 +132,14 @@ function connect() {
129
132
getEventSourceWrapper ( ) . addMessageListener ( handleMessage ) ;
130
133
131
134
function handleMessage ( event ) {
132
- if ( event . data == " \uD83D\uDC93" ) {
135
+ if ( event . data == ' \uD83D\uDC93' ) {
133
136
return ;
134
137
}
135
138
try {
136
139
processMessage ( JSON . parse ( event . data ) ) ;
137
140
} catch ( ex ) {
138
141
if ( options . warn ) {
139
- console . warn ( " Invalid HMR message: " + event . data + "\n" + ex ) ;
142
+ console . warn ( ' Invalid HMR message: ' + event . data + '\n' + ex ) ;
140
143
}
141
144
}
142
145
}
@@ -162,43 +165,47 @@ function createReporter() {
162
165
if ( typeof document !== 'undefined' && options . overlay ) {
163
166
overlay = require ( './client-overlay' ) ( {
164
167
ansiColors : options . ansiColors ,
165
- overlayStyles : options . overlayStyles
168
+ overlayStyles : options . overlayStyles ,
166
169
} ) ;
167
170
}
168
171
169
172
var styles = {
170
- errors : " color: #ff0000;" ,
171
- warnings : " color: #999933;"
173
+ errors : ' color: #ff0000;' ,
174
+ warnings : ' color: #999933;' ,
172
175
} ;
173
176
var previousProblems = null ;
174
177
function log ( type , obj ) {
175
- var newProblems = obj [ type ] . map ( function ( msg ) { return strip ( msg ) ; } ) . join ( '\n' ) ;
178
+ var newProblems = obj [ type ]
179
+ . map ( function ( msg ) {
180
+ return strip ( msg ) ;
181
+ } )
182
+ . join ( '\n' ) ;
176
183
if ( previousProblems == newProblems ) {
177
184
return ;
178
185
} else {
179
186
previousProblems = newProblems ;
180
187
}
181
188
182
189
var style = styles [ type ] ;
183
- var name = obj . name ? "'" + obj . name + "' " : "" ;
184
- var title = " [HMR] bundle " + name + " has " + obj [ type ] . length + " " + type ;
190
+ var name = obj . name ? "'" + obj . name + "' " : '' ;
191
+ var title = ' [HMR] bundle ' + name + ' has ' + obj [ type ] . length + ' ' + type ;
185
192
// NOTE: console.warn or console.error will print the stack trace
186
193
// which isn't helpful here, so using console.log to escape it.
187
194
if ( console . group && console . groupEnd ) {
188
- console . group ( "%c" + title , style ) ;
189
- console . log ( "%c" + newProblems , style ) ;
195
+ console . group ( '%c' + title , style ) ;
196
+ console . log ( '%c' + newProblems , style ) ;
190
197
console . groupEnd ( ) ;
191
198
} else {
192
199
console . log (
193
- "%c" + title + " \n\t%c" + newProblems . replace ( / \n / g, " \n\t" ) ,
194
- style + " font-weight: bold;" ,
195
- style + " font-weight: normal;"
200
+ '%c' + title + ' \n\t%c' + newProblems . replace ( / \n / g, ' \n\t' ) ,
201
+ style + ' font-weight: bold;' ,
202
+ style + ' font-weight: normal;'
196
203
) ;
197
204
}
198
205
}
199
206
200
207
return {
201
- cleanProblemsCache : function ( ) {
208
+ cleanProblemsCache : function ( ) {
202
209
previousProblems = null ;
203
210
} ,
204
211
problems : function ( type , obj ) {
@@ -219,7 +226,7 @@ function createReporter() {
219
226
} ,
220
227
useCustomOverlay : function ( customOverlay ) {
221
228
overlay = customOverlay ;
222
- }
229
+ } ,
223
230
} ;
224
231
}
225
232
@@ -228,24 +235,28 @@ var processUpdate = require('./process-update');
228
235
var customHandler ;
229
236
var subscribeAllHandler ;
230
237
function processMessage ( obj ) {
231
- switch ( obj . action ) {
232
- case " building" :
238
+ switch ( obj . action ) {
239
+ case ' building' :
233
240
if ( options . log ) {
234
241
console . log (
235
- "[HMR] bundle " + ( obj . name ? "'" + obj . name + "' " : "" ) +
236
- "rebuilding"
242
+ '[HMR] bundle ' +
243
+ ( obj . name ? "'" + obj . name + "' " : '' ) +
244
+ 'rebuilding'
237
245
) ;
238
246
}
239
247
break ;
240
- case " built" :
248
+ case ' built' :
241
249
if ( options . log ) {
242
250
console . log (
243
- "[HMR] bundle " + ( obj . name ? "'" + obj . name + "' " : "" ) +
244
- "rebuilt in " + obj . time + "ms"
251
+ '[HMR] bundle ' +
252
+ ( obj . name ? "'" + obj . name + "' " : '' ) +
253
+ 'rebuilt in ' +
254
+ obj . time +
255
+ 'ms'
245
256
) ;
246
257
}
247
- // fall through
248
- case " sync" :
258
+ // fall through
259
+ case ' sync' :
249
260
if ( obj . name && options . name && obj . name !== options . name ) {
250
261
return ;
251
262
}
@@ -290,6 +301,6 @@ if (module) {
290
301
useCustomOverlay : function useCustomOverlay ( customOverlay ) {
291
302
if ( reporter ) reporter . useCustomOverlay ( customOverlay ) ;
292
303
} ,
293
- setOptionsAndConnect : setOptionsAndConnect
304
+ setOptionsAndConnect : setOptionsAndConnect ,
294
305
} ;
295
306
}
0 commit comments