運行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 才可啟動成功