与前两篇想结合

1.安装HtmlWebpackPlugin插件

2.在webpack.config.js中配置插件(此处实例是多页面应用)

//多页面应用
plugins: [new HtmlWebpackPlugin({
    title: "页面一", //指定页面名称
    filename: "index.html",//指定生成的页面名称 默认生成在output指定的路径下
    template: "src/html/index.html", //以当前指定的页面为模板去生成
    inject: "head",
    chunks:["main","main2"] //指定index页面中引入的js文件为main.js与main2.js
}), new HtmlWebpackPlugin({
    title: "页面二",
    filename: "index2.html",
    template: "src/html/index2.html",
    inject: true, //相当"body"
    chunks:["main2"] //指定index页面中引入的js文件为main2.js
    // minify:{ //配置html的压缩
    //   removeComments:true, //设置去除注释
    //   collapseWhitespace:true //设置去除空格
    // }
    //excludeChunks: [""] 除了一些指定的js之排除在外,其余的js全部加载进来
})]

3.demo目录结构图

webpack的使用(插件HtmlWebpackPlugin)

相关文章:

  • 2020-05-22
  • 2021-12-23
  • 2021-12-15
  • 2021-11-30
  • 2021-12-05
  • 2021-11-23
  • 2021-05-19
  • 2021-11-11
猜你喜欢
  • 2021-08-15
  • 2018-05-18
  • 2021-07-13
  • 2021-06-25
  • 2021-11-19
  • 2018-01-15
  • 2019-09-15
  • 2018-01-15
相关资源
相似解决方案