html插件 (npm install html-webpack-plugin —save-dev)

  1. const HtmlWebpackPlugin = require('html-webpack-plugin')
  2. module.exports = {
  3. plugins: [
  4. new HtmlWebpackPlugin({
  5. title: 'my-webpack',
  6. path: '/dist',
  7. template: "./public/index.html",
  8. // 压缩
  9. minify: {
  10. // 移除空格
  11. collapseWhitespace: true,
  12. // 移除注释
  13. removeCommnents: true
  14. }
  15. })
  16. ]
  17. }
  • title 打包的html的title
  • filename 名称
  • path 路径 __dirname + ‘/dist’
  • template 使用指定路径的html作为模板