@@ -26,32 +26,41 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
26
26
prepareData . watch = true ;
27
27
const childProcess = await this . startWebpackProcess ( platformData , projectData , prepareData ) ;
28
28
29
- childProcess . on ( "message" , ( message : any ) => {
29
+ childProcess . on ( "message" , ( message : string | IWebpackEmitMessage ) => {
30
30
if ( message === "Webpack compilation complete." ) {
31
31
this . $logger . info ( "Webpack build done!" ) ;
32
32
resolve ( childProcess ) ;
33
33
}
34
34
35
+ message = message as IWebpackEmitMessage ;
35
36
if ( message . emittedFiles ) {
36
37
if ( isFirstWebpackWatchCompilation ) {
37
38
isFirstWebpackWatchCompilation = false ;
38
39
return ;
39
40
}
40
41
41
- const result = this . getUpdatedEmittedFiles ( message . emittedFiles , message . webpackRuntimeFiles , message . entryPointFiles ) ;
42
+ let result ;
43
+ if ( prepareData . hmr ) {
44
+ result = this . getUpdatedEmittedFiles ( message . emittedFiles , message . webpackRuntimeFiles , message . entryPointFiles ) ;
45
+ } else {
46
+ result = { emittedFiles : message . emittedFiles , fallbackFiles : [ ] , hash : "" } ;
47
+ }
42
48
43
49
const files = result . emittedFiles
44
50
. map ( ( file : string ) => path . join ( platformData . appDestinationDirectoryPath , "app" , file ) ) ;
45
51
46
52
const data = {
47
53
files,
54
+ hasOnlyHotUpdateFiles : files . every ( f => f . indexOf ( "hot-update" ) > - 1 ) ,
48
55
hmrData : {
49
56
hash : result . hash ,
50
57
fallbackFiles : result . fallbackFiles
51
58
}
52
59
} ;
53
60
54
- this . emit ( WEBPACK_COMPILATION_COMPLETE , data ) ;
61
+ if ( data . files . length ) {
62
+ this . emit ( WEBPACK_COMPILATION_COMPLETE , data ) ;
63
+ }
55
64
}
56
65
} ) ;
57
66
@@ -184,27 +193,24 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
184
193
private getUpdatedEmittedFiles ( emittedFiles : string [ ] , webpackRuntimeFiles : string [ ] , entryPointFiles : string [ ] ) {
185
194
let fallbackFiles : string [ ] = [ ] ;
186
195
let hotHash ;
187
- if ( emittedFiles . some ( x => x . endsWith ( '.hot-update.json' ) ) ) {
188
- let result = emittedFiles . slice ( ) ;
189
- const hotUpdateScripts = emittedFiles . filter ( x => x . endsWith ( '.hot-update.js' ) ) ;
190
- if ( webpackRuntimeFiles && webpackRuntimeFiles . length ) {
191
- result = result . filter ( file => webpackRuntimeFiles . indexOf ( file ) === - 1 ) ;
192
- }
193
- if ( entryPointFiles && entryPointFiles . length ) {
194
- result = result . filter ( file => entryPointFiles . indexOf ( file ) === - 1 ) ;
195
- }
196
- hotUpdateScripts . forEach ( hotUpdateScript => {
197
- const { name, hash } = this . parseHotUpdateChunkName ( hotUpdateScript ) ;
198
- hotHash = hash ;
199
- // remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
200
- result = result . filter ( file => file !== `${ name } .js` ) ;
201
- } ) ;
202
- // if applying of hot update fails, we must fallback to the full files
203
- fallbackFiles = emittedFiles . filter ( file => result . indexOf ( file ) === - 1 ) ;
204
- return { emittedFiles : result , fallbackFiles, hash : hotHash } ;
196
+ let result = emittedFiles . slice ( ) ;
197
+ const hotUpdateScripts = emittedFiles . filter ( x => x . endsWith ( '.hot-update.js' ) ) ;
198
+ if ( webpackRuntimeFiles && webpackRuntimeFiles . length ) {
199
+ result = result . filter ( file => webpackRuntimeFiles . indexOf ( file ) === - 1 ) ;
200
+ }
201
+ if ( entryPointFiles && entryPointFiles . length ) {
202
+ result = result . filter ( file => entryPointFiles . indexOf ( file ) === - 1 ) ;
205
203
}
204
+ hotUpdateScripts . forEach ( hotUpdateScript => {
205
+ const { name, hash } = this . parseHotUpdateChunkName ( hotUpdateScript ) ;
206
+ hotHash = hash ;
207
+ // remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
208
+ result = result . filter ( file => file !== `${ name } .js` ) ;
209
+ } ) ;
210
+ // if applying of hot update fails, we must fallback to the full files
211
+ fallbackFiles = emittedFiles . filter ( file => hotUpdateScripts . indexOf ( file ) === - 1 ) ;
206
212
207
- return { emittedFiles, fallbackFiles } ;
213
+ return { emittedFiles : result , fallbackFiles, hash : hotHash } ;
208
214
}
209
215
210
216
private parseHotUpdateChunkName ( name : string ) {
0 commit comments