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