@@ -29,14 +29,13 @@ class Watcher extends EventEmitter {
29
29
}
30
30
port : number ;
31
31
closed : boolean ;
32
+ live : boolean ;
33
+ hot : boolean ;
32
34
33
35
dev_server : DevServer ;
34
36
proc : child_process . ChildProcess ;
35
37
filewatchers : Array < { close : ( ) => void } > ;
36
- deferreds : {
37
- client : Deferred ;
38
- server : Deferred ;
39
- } ;
38
+ deferred : Deferred ;
40
39
41
40
crashed : boolean ;
42
41
restarting : boolean ;
@@ -51,6 +50,8 @@ class Watcher extends EventEmitter {
51
50
app = locations . app ( ) ,
52
51
dest = locations . dest ( ) ,
53
52
routes = locations . routes ( ) ,
53
+ live,
54
+ hot,
54
55
bundler,
55
56
webpack = 'webpack' ,
56
57
rollup = 'rollup' ,
@@ -59,6 +60,8 @@ class Watcher extends EventEmitter {
59
60
app : string ,
60
61
dest : string ,
61
62
routes : string ,
63
+ live : boolean ,
64
+ hot : boolean ,
62
65
bundler ?: string ,
63
66
webpack : string ,
64
67
rollup : string ,
@@ -71,6 +74,9 @@ class Watcher extends EventEmitter {
71
74
this . port = port ;
72
75
this . closed = false ;
73
76
77
+ this . live = live ;
78
+ this . hot = hot ;
79
+
74
80
this . filewatchers = [ ] ;
75
81
76
82
this . current_build = {
@@ -159,10 +165,7 @@ class Watcher extends EventEmitter {
159
165
} )
160
166
) ;
161
167
162
- this . deferreds = {
163
- server : new Deferred ( ) ,
164
- client : new Deferred ( )
165
- } ;
168
+ let deferred = new Deferred ( ) ;
166
169
167
170
// TODO watch the configs themselves?
168
171
const compilers : Compilers = create_compilers ( this . bundler , {
@@ -187,11 +190,10 @@ class Watcher extends EventEmitter {
187
190
188
191
invalid : filename => {
189
192
this . restart ( filename , 'server' ) ;
190
- this . deferreds . server = new Deferred ( ) ;
191
193
} ,
192
194
193
195
handle_result : ( result : CompileResult ) => {
194
- this . deferreds . client . promise . then ( ( ) => {
196
+ deferred . promise . then ( ( ) => {
195
197
const restart = ( ) => {
196
198
log = '' ;
197
199
this . crashed = false ;
@@ -203,11 +205,15 @@ class Watcher extends EventEmitter {
203
205
process : this . proc
204
206
} ) ;
205
207
206
- this . deferreds . server . fulfil ( ) ;
207
-
208
- this . dev_server . send ( {
209
- status : 'completed'
210
- } ) ;
208
+ if ( this . live ) {
209
+ this . dev_server . send ( {
210
+ action : 'reload'
211
+ } ) ;
212
+ } else {
213
+ this . dev_server . send ( {
214
+ status : 'completed'
215
+ } ) ;
216
+ }
211
217
} ) )
212
218
. catch ( err => {
213
219
if ( this . crashed ) return ;
@@ -263,7 +269,7 @@ class Watcher extends EventEmitter {
263
269
264
270
invalid : filename => {
265
271
this . restart ( filename , 'client' ) ;
266
- this . deferreds . client = new Deferred ( ) ;
272
+ deferred = new Deferred ( ) ;
267
273
268
274
// TODO we should delete old assets. due to a webpack bug
269
275
// i don't even begin to comprehend, this is apparently
@@ -276,7 +282,6 @@ class Watcher extends EventEmitter {
276
282
shimport : this . bundler === 'rollup' && require ( 'shimport/package.json' ) . version ,
277
283
assets : result . assetsByChunkName
278
284
} , null , ' ' ) ) ;
279
- this . deferreds . client . fulfil ( ) ;
280
285
281
286
const client_files = result . assets . map ( ( file : string ) => `client/${ file } ` ) ;
282
287
@@ -285,6 +290,8 @@ class Watcher extends EventEmitter {
285
290
client_files
286
291
} ) ;
287
292
293
+ deferred . fulfil ( ) ;
294
+
288
295
// we need to wait a beat before watching the service
289
296
// worker, because of some webpack nonsense
290
297
setTimeout ( watch_serviceworker , 100 ) ;
0 commit comments