Skip to content

Commit f127953

Browse files
authored
Add support for Webpack 4 webhooks (#139)
1 parent c8cfdb3 commit f127953

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function StaticSiteGeneratorWebpackPlugin(options) {
2222
StaticSiteGeneratorWebpackPlugin.prototype.apply = function(compiler) {
2323
var self = this;
2424

25-
compiler.plugin('this-compilation', function(compilation) {
26-
compilation.plugin('optimize-assets', function(_, done) {
25+
addThisCompilationHandler(compiler, function(compilation) {
26+
addOptimizeAssetsHandler(compilation, function(_, done) {
2727
var renderPromises;
2828

2929
var webpackStats = compilation.getStats();
@@ -228,4 +228,22 @@ function legacyArgsToOptions(entry, paths, locals, globals) {
228228
};
229229
}
230230

231+
function addThisCompilationHandler(compiler, callback) {
232+
if(compiler.hooks) {
233+
/* istanbul ignore next */
234+
compiler.hooks.thisCompilation.tap('static-site-generator-webpack-plugin', callback);
235+
} else {
236+
compiler.plugin('this-compilation', callback);
237+
}
238+
}
239+
240+
function addOptimizeAssetsHandler(compilation, callback) {
241+
if(compilation.hooks) {
242+
/* istanbul ignore next */
243+
compilation.hooks.optimizeAssets.tapAsync('static-site-generator-webpack-plugin',callback);
244+
} else {
245+
compilation.plugin('optimize-assets', callback);
246+
}
247+
}
248+
231249
module.exports = StaticSiteGeneratorWebpackPlugin;

0 commit comments

Comments
 (0)