diff --git a/index.js b/index.js index fbdd58e..f8543f6 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,8 @@ require('object.values').shim(); const objectAssign = require('object-assign'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); + const PLUGIN_NAME = 'preload-webpack-plugin'; const weblog = require('webpack-log'); @@ -97,13 +99,15 @@ class PreloadPlugin { // handler use for webpack v4 hooksHandler(compilation) { - if (!compilation.hooks.htmlWebpackPluginAfterHtmlProcessing) { + const beforeEmit = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing || + HtmlWebpackPlugin.getHooks(compilation).beforeEmit; + if (!beforeEmit) { const message = `compilation.hooks.htmlWebpackPluginAfterHtmlProcessing is lost. Please make sure you have installed html-webpack-plugin and put it before ${PLUGIN_NAME}`; log.error(message); throw new Error(message); } - compilation.hooks.htmlWebpackPluginAfterHtmlProcessing + beforeEmit .tapAsync(PLUGIN_NAME, (htmlPluginData, cb) => this.afterHtmlProcessingFn(htmlPluginData, cb, compilation)); } diff --git a/package.json b/package.json index 9722559..d8b81bc 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "preload-webpack-plugin", - "version": "2.3.0", + "version": "2.3.1", "description": "Enhances html-webpack-plugin with link rel=preload wiring capabilities for scripts", "main": "index.js", "scripts": { "lint": "eslint --quiet -f codeframe index.js test/spec.js", "lint-fix": "eslint --fix --quiet -f codeframe index.js test/spec.js", + "prewebpack-v3-t": "cd test/webpack-v3 && npm install", "webpack-v3-t": "node_modules/jasmine/bin/jasmine.js test/webpack-v3.spec.js", "test": "node_modules/jasmine/bin/jasmine.js test/spec.js && npm run webpack-v3-t" }, @@ -42,7 +43,8 @@ "webpack": "^4.1.0" }, "peerDependencies": { - "webpack": "^4.0.1" + "webpack": "^4.0.1", + "html-webpack-plugin": "^3.0.6" }, "dependencies": { "object-assign": "^4.1.1",