Skip to content

Commit 8aa4e25

Browse files
authored
fix: add support for html-webpack-plugin@4 (#134)
Fixes #132
1 parent 984ac97 commit 8aa4e25

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"eslint": "^5.6.0",
5454
"eslint-config-simenb-base": "^15.0.0",
5555
"eslint_d": "^7.1.0",
56-
"html-webpack-plugin": "^3.0.4",
56+
"html-webpack-plugin": "^4.0.0-0",
5757
"husky": "^0.14.3",
5858
"jest": "^23.6.0",
5959
"jest-watch-typeahead": "^0.2.0",
@@ -65,7 +65,7 @@
6565
"webpack-cli": "^3.1.0"
6666
},
6767
"peerDependencies": {
68-
"html-webpack-plugin": "^3.0.4"
68+
"html-webpack-plugin": "^3.0.4 || ^4.0.0-0"
6969
},
7070
"engines": {
7171
"node": ">=6"

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import HtmlWebpackPlugin from 'html-webpack-plugin';
12
import addAllAssetsToCompilation from './addAllAssetsToCompilation';
23

34
export default class AddAssetHtmlPlugin {
@@ -8,10 +9,15 @@ export default class AddAssetHtmlPlugin {
89
/* istanbul ignore next: this would be integration tests */
910
apply(compiler) {
1011
compiler.hooks.compilation.tap('AddAssetHtmlPlugin', compilation => {
11-
compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tapPromise(
12-
'AddAssetHtmlPlugin',
13-
htmlPluginData =>
14-
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData),
12+
let hook;
13+
if (HtmlWebpackPlugin.version === 4) {
14+
hook = HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration;
15+
} else {
16+
hook = compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration;
17+
}
18+
19+
hook.tapPromise('AddAssetHtmlPlugin', htmlPluginData =>
20+
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData),
1521
);
1622
});
1723
}

yarn.lock

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@
551551
dependencies:
552552
any-observable "^0.3.0"
553553

554+
555+
version "1.0.2"
556+
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd"
557+
554558
"@webassemblyjs/[email protected]":
555559
version "1.7.6"
556560
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.6.tgz#3ef8c45b3e5e943a153a05281317474fef63e21e"
@@ -2877,16 +2881,16 @@ html-minifier@^3.2.3:
28772881
relateurl "0.2.x"
28782882
uglify-js "3.4.x"
28792883

2880-
html-webpack-plugin@^3.0.4:
2881-
version "3.2.0"
2882-
resolved "http://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b"
2884+
html-webpack-plugin@^4.0.0-0:
2885+
version "4.0.0-alpha.2"
2886+
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-4.0.0-alpha.2.tgz#7745967e389a57a098e26963f328ebe4c19b598d"
28832887
dependencies:
2888+
"@types/tapable" "1.0.2"
28842889
html-minifier "^3.2.3"
2885-
loader-utils "^0.2.16"
2886-
lodash "^4.17.3"
2890+
loader-utils "^1.1.0"
2891+
lodash "^4.17.10"
28872892
pretty-error "^2.0.2"
28882893
tapable "^1.0.0"
2889-
toposort "^1.0.0"
28902894
util.promisify "1.0.0"
28912895

28922896
htmlparser2@~3.3.0:
@@ -3994,15 +3998,6 @@ loader-runner@^2.3.0:
39943998
version "2.3.0"
39953999
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
39964000

3997-
loader-utils@^0.2.16:
3998-
version "0.2.17"
3999-
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
4000-
dependencies:
4001-
big.js "^3.1.3"
4002-
emojis-list "^2.0.0"
4003-
json5 "^0.5.0"
4004-
object-assign "^4.0.1"
4005-
40064001
loader-utils@^1.1.0:
40074002
version "1.1.0"
40084003
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
@@ -4033,7 +4028,7 @@ lodash.sortby@^4.7.0:
40334028
version "4.7.0"
40344029
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
40354030

4036-
lodash@^4.0.1, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5:
4031+
lodash@^4.0.1, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5:
40374032
version "4.17.11"
40384033
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
40394034

@@ -5881,10 +5876,6 @@ to-regex@^3.0.1, to-regex@^3.0.2:
58815876
regex-not "^1.0.2"
58825877
safe-regex "^1.1.0"
58835878

5884-
toposort@^1.0.0:
5885-
version "1.0.7"
5886-
resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029"
5887-
58885879
tough-cookie@>=2.3.3, tough-cookie@^2.3.4, tough-cookie@~2.4.3:
58895880
version "2.4.3"
58905881
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.4.3.tgz#53f36da3f47783b0925afa06ff9f3b165280f781"

0 commit comments

Comments
 (0)