Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

compatible with html-webpack-plugin v4 hooks #81

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
}

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down