您的位置:首页 > Web前端 > HTML

webpack的使用(插件HtmlWebpackPlugin)

2018-03-30 16:03 1251 查看
与前两篇想结合
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目录结构图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: