webpack4: compilation.mainTemplate.applyPluginsWaterfall is not a function 解决方法

今天捣鼓webpack4踩到一个弥天大坑:使用html-webpack-plugin打包html的时候一直报 compilation.mainTemplate.applyPluginsWaterfall is not a function ,百度了半天没结果,谷歌一下终于在github上找到了解决方案:https://github.com/jantimon/html-webpack-plugin/issues/841

解决:先安装yarn,然后在项目跟目录下运行:

yarn add webpack-contrib/html-webpack-plugin -D

简单来说就是使用webpack官方维护的html-webpack-plugin来代替第三方的。