1- const log = console ;
1+ const hmrPrefix = 'HMR:' ;
2+ const log = {
3+ info : ( message ) => console . info ( `${ hmrPrefix } ${ message } ` ) ,
4+ warn : ( message ) => console . warn ( `${ hmrPrefix } ${ message } ` ) ,
5+ error : ( message ) => console . error ( `${ hmrPrefix } ${ message } ` ) ,
6+ } ;
27const refresh = 'Application needs to be restarted in order to apply the changes.' ;
38const hotOptions = {
49 ignoreUnaccepted : true ,
@@ -45,19 +50,19 @@ function result(modules, appliedModules) {
4550 }
4651
4752 if ( ! ( appliedModules || [ ] ) . length ) {
48- console . info ( 'No Modules Updated.' ) ;
53+ log . info ( 'No Modules Updated.' ) ;
4954 } else {
50- console . info ( 'The following modules were updated:' ) ;
55+ log . info ( 'The following modules were updated:' ) ;
5156
5257 for ( const moduleId of appliedModules ) {
53- console . info ( ` ↻ ${ moduleId } ` ) ;
58+ log . info ( ` ↻ ${ moduleId } ` ) ;
5459 }
5560
5661 const numberIds = appliedModules . every (
5762 ( moduleId ) => typeof moduleId === 'number'
5863 ) ;
5964 if ( numberIds ) {
60- console . info (
65+ log . info (
6166 'Please consider using the NamedModulesPlugin for module names.'
6267 ) ;
6368 }
@@ -85,7 +90,7 @@ function check(options) {
8590 result ( modules , appliedModules ) ;
8691
8792 if ( upToDate ( ) ) {
88- console . info ( 'App is up to date.' ) ;
93+ log . info ( 'App is up to date.' ) ;
8994 }
9095 } )
9196 . catch ( ( err ) => {
@@ -97,7 +102,7 @@ function check(options) {
97102 window . location . reload ( ) ;
98103 }
99104 } else {
100- log . warn ( `Update failed: ${ err . stack } ` || err . message ) ;
105+ log . warn ( `Update failed: ${ err . stack || err . message } ` ) ;
101106 }
102107 } ) ;
103108 } )
@@ -107,15 +112,15 @@ function check(options) {
107112 log . warn ( `Cannot check for update. ${ refresh } ` ) ;
108113 log . warn ( err . stack || err . message ) ;
109114 } else {
110- log . warn ( `Update check failed: ${ err . stack } ` || err . message ) ;
115+ log . warn ( `Update check failed: ${ err . stack || err . message } ` ) ;
111116 }
112117 } ) ;
113118}
114119
115120if ( module . hot ) {
116- console . info ( 'Hot Module Replacement Enabled. Waiting for signal.' ) ;
121+ log . info ( 'Hot Module Replacement Enabled. Waiting for signal.' ) ;
117122} else {
118- console . error ( 'Hot Module Replacement is disabled.' ) ;
123+ log . error ( 'Hot Module Replacement is disabled.' ) ;
119124}
120125
121126function update ( currentHash , options ) {
@@ -124,7 +129,7 @@ function update(currentHash, options) {
124129 const status = module . hot . status ( ) ;
125130
126131 if ( status === 'idle' ) {
127- console . info ( 'Checking for updates to the bundle.' ) ;
132+ log . info ( 'Checking for updates to the bundle.' ) ;
128133 check ( options ) ;
129134 } else if ( [ 'abort' , 'fail' ] . indexOf ( status ) >= 0 ) {
130135 log . warn (
0 commit comments