webpack中插件升级后的配置选项的写法

159 阅读1分钟

1、webpack中"html-loader": "^1.3.2"插件版本的options和老版本的options写法看下图

2、webpack中"html-webpack-plugin": "^4.5.0"插件版本的配置选项的写法

在webpack的配置文件内的plugins选项内

plugins: [
    new HtmlWebpackPlugin({
      title: '自动打包后的html文件的标题', // 需要在html的模板文件内,加入模板语法才行
      filename: 'aaa.html', // 修改打包后的文件的名字
      template: './index.html' // 以哪个html文件为模板,打包后生成新的html文件
    })
  ],

在html的模板文件内加入模板语法,webpack配置文件中的html-ebpack-plugin插件内的title属性才会生效

<head>
  <!-- <title>Document</title> -->
  // 进行如下配置才行
  <title><%= htmlWebpackPlugin.options.title %></title>
</head>