From 8ecfc342bc224924a590c913828914fbaea0627f Mon Sep 17 00:00:00 2001 From: John Mai Date: Tue, 12 Feb 2019 13:02:30 +0800 Subject: [PATCH 1/3] update support html-webpack-plugin 4.x --- package.json | 1 + src/plugin.js | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6615bbd..a46944c 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/plugin.js b/src/plugin.js index cf6743f..d160bc1 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -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. @@ -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); }); } } From 5771af815b553c2191f672ed7e4f2896dfa41d22 Mon Sep 17 00:00:00 2001 From: John Mai Date: Tue, 12 Feb 2019 13:17:08 +0800 Subject: [PATCH 2/3] add prepublish --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a46944c..071a57f 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "build:watch": "npm run cleanup && babel src --out-dir lib --watch", "prepublishOnly": "npm run build", "precommit": "del-cli yarn.lock && lint-staged && npm run test", - "format": "prettier-eslint --print-width 100 --trailing-comma es5 --single-quote --write \"{{src,specs,scripts,examples/**/src,experiments/**/src}/**/*.{js,json,css},*.{js,json}}\" " + "format": "prettier-eslint --print-width 100 --trailing-comma es5 --single-quote --write \"{{src,specs,scripts,examples/**/src,experiments/**/src}/**/*.{js,json,css},*.{js,json}}\" ", + "prepublish": "npm run build" }, "files": [ "src", From 8d46f78c48e32c4f5d284c4b9383bd85a128fb10 Mon Sep 17 00:00:00 2001 From: John Mai Date: Tue, 12 Feb 2019 14:12:08 +0800 Subject: [PATCH 3/3] update support html-webpack-plugin 4.x --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 071a57f..a46944c 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,7 @@ "build:watch": "npm run cleanup && babel src --out-dir lib --watch", "prepublishOnly": "npm run build", "precommit": "del-cli yarn.lock && lint-staged && npm run test", - "format": "prettier-eslint --print-width 100 --trailing-comma es5 --single-quote --write \"{{src,specs,scripts,examples/**/src,experiments/**/src}/**/*.{js,json,css},*.{js,json}}\" ", - "prepublish": "npm run build" + "format": "prettier-eslint --print-width 100 --trailing-comma es5 --single-quote --write \"{{src,specs,scripts,examples/**/src,experiments/**/src}/**/*.{js,json,css},*.{js,json}}\" " }, "files": [ "src",