11const path = require ( 'path' ) ;
22const fs = require ( 'fs' ) ;
33const querystring = require ( 'querystring' ) ;
4- const { SyncHook } = require ( 'tapable' ) ;
54
65const util = require ( './util' ) ;
76const HTMLDocument = require ( './HTMLDocument' ) ;
@@ -95,9 +94,6 @@ class WebPlugin {
9594 const { options } = this ;
9695 const { template, requires, filename, outputPagemap, outputPagemapFilename } = options ;
9796
98- // inject hooks
99- compiler . hooks . webPluginBeforeEmitHTML = new SyncHook ( [ 'htmlDocument' ] ) ;
100-
10197 // get webpack compiler's env
10298 if ( global . _isProduction === undefined ) {
10399 global . _isProduction = util . isProduction ( compiler ) ;
@@ -111,9 +107,9 @@ class WebPlugin {
111107 // watch for file changed event
112108 compiler . hooks . watchRun . tap ( 'WebPlugin' , ( watching ) => {
113109 // 发生变化的文件列表
114- const changedTimes = watching . watchFileSystem . watcher . mtimes ;
110+ const changedTimes = watching . watchFileSystem ? .watcher ? .mtimes ;
115111 // 如果 HTML 模版文件发生了变化就重新编译模版文件
116- if ( changedTimes [ template ] !== undefined ) {
112+ if ( changedTimes && changedTimes [ template ] !== undefined ) {
117113 // html template file has changed, re build this.htmlDocument
118114 this . buildHtmlDocument ( ) ;
119115 }
@@ -158,7 +154,6 @@ class WebPlugin {
158154 } ) ;
159155
160156 // get html document string
161- compiler . hooks . webPluginBeforeEmitHTML . call ( this . htmlDocument ) ;
162157 const htmlOut = this . htmlDocument . serialize ( ) ;
163158 // add it to webpack output files
164159 util . addFileToWebpackOutput ( compilation , filename , htmlOut ) ;
0 commit comments