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目录结构图
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目录结构图
相关文章推荐
- html-webpack-plugin插件使用chunks属性时报错
- html-webpack-plugin插件的详细介绍和使用
- [js高手之路]深入浅出webpack教程系列4-插件使用之html-webpack-plugin配置(上)
- webpack插件:使用HtmlWebpackPlugin在页面中使用EJS语法引用模板文件(二)
- [js高手之路]深入浅出webpack教程系列5-插件使用之html-webpack-plugin配置(中)
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
- webpack 插件html-webpack-plugin的具体使用
- HtmlWebpackPlugin插件使用实现html文件自动生成
- [js高手之路]深入浅出webpack教程系列4-插件使用之html-webpack-plugin配置(上)
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
- webpack 插件: html-webpack-plugin
- webpack 插件: html-webpack-plugin
- webpack插件html-webpack-plugin
- html-webpack-plugin插件 根据模板生成多页面
- webpack.optimize.CommonsChunkPlugin插件的使用
- webpack---htmlWbpackPlugin插件在webpack中的应用
- HTML Webpack Plugin 插件参数学习
- html-webpack-plugin 中使用 title选项设置模版中的值无效
- webpack插件html-webpack-plugin
- webpack 插件之Html-Webpack-Plugin