Skip to content

Commit

Permalink
Add support for Webpack 4 webhooks (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
jahredhope committed Nov 19, 2018
1 parent c8cfdb3 commit f127953
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions index.js
Expand Up @@ -22,8 +22,8 @@ function StaticSiteGeneratorWebpackPlugin(options) {
StaticSiteGeneratorWebpackPlugin.prototype.apply = function(compiler) {
var self = this;

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

var webpackStats = compilation.getStats();
Expand Down Expand Up @@ -228,4 +228,22 @@ function legacyArgsToOptions(entry, paths, locals, globals) {
};
}

function addThisCompilationHandler(compiler, callback) {
if(compiler.hooks) {
/* istanbul ignore next */
compiler.hooks.thisCompilation.tap('static-site-generator-webpack-plugin', callback);
} else {
compiler.plugin('this-compilation', callback);
}
}

function addOptimizeAssetsHandler(compilation, callback) {
if(compilation.hooks) {
/* istanbul ignore next */
compilation.hooks.optimizeAssets.tapAsync('static-site-generator-webpack-plugin',callback);
} else {
compilation.plugin('optimize-assets', callback);
}
}

module.exports = StaticSiteGeneratorWebpackPlugin;

0 comments on commit f127953

Please sign in to comment.