设置 HtmlWebpackPlugin
首先安装插件
编辑 webpakc.config.js
我们可以先删除 dist 文件,然后执行npm run build
可以看到重新生成了 dist 文件夹,此时文件结构为
在浏览器中打开dist
文件夹中的index.html
我们可以在页面中看到我们hello webpack
,并且控制台中有输出hello webpack
但是其实我们之前的index.html
并没有引入index.js
,但HtmlWebpackPlugin
会帮我们引入自动引入
去查看打包后的index.html
可以找到