Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update support html-webpack-plugin 4.x #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
]
},
"peerDependencies": {
"html-webpack-plugin": "^3.0.4 || ^4.0.0-0",
"webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
},
"dependencies": {
Expand Down
18 changes: 13 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import getInstanceIndex from './getInstanceIndex';
import createHandleStats from './createHandleStats';
import createLogger from './createLogger';

import HtmlWebpackPlugin from 'html-webpack-plugin';

class AutoDLLPlugin {
constructor(settings) {
// first, we store a reference to the settings passed by the user as is.
Expand Down Expand Up @@ -136,14 +138,20 @@ class AutoDLLPlugin {
};

compiler.hooks.compilation.tap('AutoDllPlugin', compilation => {
if (!compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration) {
let beforeGenerationHook;
if (compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration) {
// HtmlWebpackPlugin 3.x
beforeGenerationHook = compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration;
} else if (HtmlWebpackPlugin.version === 4) {
// HtmlWebpackPlugin >= 4.x
beforeGenerationHook = HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration;
}

if (!beforeGenerationHook) {
return;
}

compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tapAsync(
'AutoDllPlugin',
doCompilation
);
beforeGenerationHook.tapAsync('AutoDllPlugin', doCompilation);
});
}
}
Expand Down