@@ -21,14 +21,13 @@ const childCompiler = require('./lib/compiler.js');
21
21
const prettyError = require ( './lib/errors.js' ) ;
22
22
const chunkSorter = require ( './lib/chunksorter.js' ) ;
23
23
const getHtmlWebpackPluginHooks = require ( './lib/hooks.js' ) . getHtmlWebpackPluginHooks ;
24
- const getHtmlWebpackPluginHook = require ( './lib/hooks.js' ) . getHtmlWebpackPluginHook ;
25
24
26
25
const fsStatAsync = promisify ( fs . stat ) ;
27
26
const fsReadFileAsync = promisify ( fs . readFile ) ;
28
27
29
28
class HtmlWebpackPlugin {
30
29
/**
31
- * @param {Partial<HtmlWebpackPluginOptions> } options
30
+ * @param {Partial<HtmlWebpackPluginOptions> } [ options]
32
31
*/
33
32
constructor ( options ) {
34
33
// Default options
@@ -60,10 +59,7 @@ class HtmlWebpackPlugin {
60
59
this . childCompilationOutputName = undefined ;
61
60
this . assetJson = undefined ;
62
61
this . hash = undefined ;
63
- /**
64
- * The major version number of this plugin
65
- */
66
- this . version = 4 ;
62
+ this . version = HtmlWebpackPlugin . version ;
67
63
}
68
64
69
65
/**
@@ -173,7 +169,7 @@ class HtmlWebpackPlugin {
173
169
} )
174
170
// Allow plugins to make changes to the assets before invoking the template
175
171
// This only makes sense to use if `inject` is `false`
176
- . then ( compilationResult => getHtmlWebpackPluginHook ( compilation , 'htmlWebpackPluginBeforeHtmlGeneration' ) . promise ( {
172
+ . then ( compilationResult => getHtmlWebpackPluginHooks ( compilation ) . htmlWebpackPluginBeforeHtmlGeneration . promise ( {
177
173
assets : assets ,
178
174
outputName : self . childCompilationOutputName ,
179
175
plugin : self
@@ -186,7 +182,7 @@ class HtmlWebpackPlugin {
186
182
// Allow plugins to change the html before assets are injected
187
183
. then ( html => {
188
184
const pluginArgs = { html : html , assets : assets , plugin : self , outputName : self . childCompilationOutputName } ;
189
- return getHtmlWebpackPluginHook ( compilation , 'htmlWebpackPluginBeforeHtmlProcessing' ) . promise ( pluginArgs ) ;
185
+ return getHtmlWebpackPluginHooks ( compilation ) . htmlWebpackPluginBeforeHtmlProcessing . promise ( pluginArgs ) ;
190
186
} )
191
187
. then ( result => {
192
188
const html = result . html ;
@@ -195,7 +191,7 @@ class HtmlWebpackPlugin {
195
191
const assetTags = self . generateHtmlTagObjects ( assets ) ;
196
192
const pluginArgs = { head : assetTags . head , body : assetTags . body , plugin : self , outputName : self . childCompilationOutputName } ;
197
193
// Allow plugins to change the assetTag definitions
198
- return getHtmlWebpackPluginHook ( compilation , 'htmlWebpackPluginAlterAssetTags' ) . promise ( pluginArgs )
194
+ return getHtmlWebpackPluginHooks ( compilation ) . htmlWebpackPluginAlterAssetTags . promise ( pluginArgs )
199
195
. then ( result => self . postProcessHtml ( html , assets , { body : result . body , head : result . head } )
200
196
. then ( html => _ . extend ( result , { html : html , assets : assets } ) ) ) ;
201
197
} )
@@ -204,7 +200,7 @@ class HtmlWebpackPlugin {
204
200
const html = result . html ;
205
201
const assets = result . assets ;
206
202
const pluginArgs = { html : html , assets : assets , plugin : self , outputName : self . childCompilationOutputName } ;
207
- return getHtmlWebpackPluginHook ( compilation , 'htmlWebpackPluginAfterHtmlProcessing' ) . promise ( pluginArgs )
203
+ return getHtmlWebpackPluginHooks ( compilation ) . htmlWebpackPluginAfterHtmlProcessing . promise ( pluginArgs )
208
204
. then ( result => result . html ) ;
209
205
} )
210
206
. catch ( err => {
@@ -222,7 +218,7 @@ class HtmlWebpackPlugin {
222
218
size : ( ) => html . length
223
219
} ;
224
220
} )
225
- . then ( ( ) => getHtmlWebpackPluginHook ( compilation , 'htmlWebpackPluginAfterEmit' ) . promise ( {
221
+ . then ( ( ) => getHtmlWebpackPluginHooks ( compilation ) . htmlWebpackPluginAfterEmit . promise ( {
226
222
html : compilation . assets [ self . childCompilationOutputName ] ,
227
223
outputName : self . childCompilationOutputName ,
228
224
plugin : self
@@ -697,4 +693,18 @@ function templateParametersGenerator (compilation, assets, options) {
697
693
}
698
694
} ;
699
695
}
696
+
697
+ // Statics:
698
+ /**
699
+ * The major version number of this plugin
700
+ */
701
+ HtmlWebpackPlugin . version = 4 ;
702
+
703
+ /**
704
+ * A static helper to get the hooks for this plugin
705
+ *
706
+ * Usage: HtmlWebpackPlugin.getHook(compilation, 'HookName').tap('YourPluginName', () => { ... });
707
+ */
708
+ HtmlWebpackPlugin . getHooks = getHtmlWebpackPluginHooks ;
709
+
700
710
module . exports = HtmlWebpackPlugin ;
0 commit comments