运行yarn webpack打包项目报错HtmlWebpackPlugin is not defined,采坑过程升级webpack-cli版本、降低webpack版本都没有作用,我的项目中使用的是webpack5版本。
image.png
解决方案:
在webpack.config.js 文件中
const HtmlwebpackPlugin = require("html-webpack-plugin");
...
plugins: [
new HtmlwebpackPlugin ({
// template: "./index.html", //指定模板路径
filename: "./dist/index.html", //指定文件名
}),
],
改为
const htmlWebpackPlugin = require("html-webpack-plugin");
...
plugins: [
new htmlWebpackPlugin({
// template: "./index.html", //指定模板路径
filename: "./dist/index.html", //指定文件名
}),
],
首先确保安装webpack、webpack-cli、html-webpack-plugin 才可启动成功