@@ -214,29 +214,28 @@ var OfflinePlugin = (function () {
214214 _this2 . resolveToolPaths ( tool , key , compiler ) ;
215215 } ) ;
216216
217- compiler . plugin ( 'normal-module-factory' , function ( nmf ) {
218- nmf . plugin ( 'after-resolve' , function ( result , callback ) {
219- var resource = _path3 [ 'default' ] . resolve ( compiler . context , result . resource ) ;
217+ var afterResolveFn = function afterResolveFn ( result , callback ) {
218+ var resource = _path3 [ 'default' ] . resolve ( compiler . context , result . resource ) ;
220219
221- if ( resource !== runtimePath ) {
222- return callback ( null , result ) ;
223- }
220+ if ( resource !== runtimePath ) {
221+ callback ( null , result ) ;
222+ return ;
223+ }
224224
225- var data = {
226- autoUpdate : _this2 . autoUpdate
227- } ;
225+ var data = {
226+ autoUpdate : _this2 . autoUpdate
227+ } ;
228228
229- _this2 . useTools ( function ( tool , key ) {
230- data [ key ] = tool . getConfig ( _this2 ) ;
231- } ) ;
229+ _this2 . useTools ( function ( tool , key ) {
230+ data [ key ] = tool . getConfig ( _this2 ) ;
231+ } ) ;
232232
233- result . loaders . push ( _path3 [ 'default' ] . join ( __dirname , 'misc/runtime-loader.js' ) + '?' + JSON . stringify ( data ) ) ;
233+ result . loaders . push ( _path3 [ 'default' ] . join ( __dirname , 'misc/runtime-loader.js' ) + '?' + JSON . stringify ( data ) ) ;
234234
235- callback ( null , result ) ;
236- } ) ;
237- } ) ;
235+ callback ( null , result ) ;
236+ } ;
238237
239- compiler . plugin ( 'make' , function ( compilation , callback ) {
238+ var makeFn = function makeFn ( compilation , callback ) {
240239 if ( _this2 . warnings . length ) {
241240 [ ] . push . apply ( compilation . warnings , _this2 . warnings ) ;
242241 }
@@ -252,9 +251,9 @@ var OfflinePlugin = (function () {
252251 } ) [ 'catch' ] ( function ( e ) {
253252 throw e || new Error ( 'Something went wrong' ) ;
254253 } ) ;
255- } ) ;
254+ } ;
256255
257- compiler . plugin ( 'emit' , function ( compilation , callback ) {
256+ var emitFn = function emitFn ( compilation , callback ) {
258257 var runtimeTemplatePath = _path3 [ 'default' ] . resolve ( __dirname , '../tpls/runtime-template.js' ) ;
259258 var hasRuntime = true ;
260259
@@ -295,7 +294,27 @@ var OfflinePlugin = (function () {
295294 } , function ( ) {
296295 callback ( new Error ( 'Something went wrong' ) ) ;
297296 } ) ;
298- } ) ;
297+ } ;
298+
299+ if ( compiler . hooks ) {
300+ ( function ( ) {
301+ var plugin = { name : 'OfflinePlugin' } ;
302+
303+ compiler . hooks . normalModuleFactory . tap ( plugin , function ( nmf ) {
304+ nmf . hooks . afterResolve . tapAsync ( plugin , afterResolveFn ) ;
305+ } ) ;
306+
307+ compiler . hooks . make . tapAsync ( plugin , makeFn ) ;
308+ compiler . hooks . emit . tapAsync ( plugin , emitFn ) ;
309+ } ) ( ) ;
310+ } else {
311+ compiler . plugin ( 'normal-module-factory' , function ( nmf ) {
312+ nmf . plugin ( 'after-resolve' , afterResolveFn ) ;
313+ } ) ;
314+
315+ compiler . plugin ( 'make' , makeFn ) ;
316+ compiler . plugin ( 'emit' , emitFn ) ;
317+ }
299318 }
300319 } , {
301320 key : 'setAssets' ,
0 commit comments