1. const HtmlWebpackPlugin = require('html-webpack-plugin')
  2. plugins: [
  3. new HtmlWebpackPlugin({
  4. template: "./src/html/index.html",
  5. filename: "./html/webJHtml.html" // 名字前加文件夹名字会自动打包到指定的文件夹里, 如果没有文件夹会自动生成文件夹
  6. })
  7. ],

1️⃣ html-webpack-plugin

npm i --save-dev html-webpack-plugin@4

  1. 1. webpack4 要安装4版本的 html-webpack-plugin
  2. 2. webpack5 要安装5版本的 html-webpack-plugin

2️⃣ 配置插件的输出结果

image.png

2️⃣ html 模板

image.png

2️⃣ 生成的 html 文件

image.png