HtmlWebpackPlugin@3

HtmlWebpackPlugin

版本号:"webpack-dev-server": "^3.10.1"

html-webpack-plugin@3 是较旧的版本(最新主版本已到5.x),主要适配 Webpack 4 及更早版本

npm install html-webpack-plugin@3 -D
yarn add html-webpack-plugin@3 -D

基本配置

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index.js',
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',  // 自定义模板
      filename: 'index.html',        // 输出文件名
      hash: true,                    // 为资源添加哈希(如 bundle.js?d2h8d)
      minify: {                      // 压缩 HTML(生产环境)
        collapseWhitespace: true,
        removeComments: true
      },
      inject: 'body' // 注入资源的位置(head|body|true|false)
    })
  ]
};
posted @ 2025-02-16 20:54  HuangBingQuan  阅读(49)  评论(0)    收藏  举报