1 当前目录

2 webpack.config.js 配置

const webpack = require('webpack'),
htmlWebpackPlugin = require('html-webpack-plugin'),
path = require('path'); module.exports = {
entry: {
main: './src/script/main.js',
a: './src/script/a.js',
b: './src/script/b.js',
c: './src/script/c.js'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'js/[name]-[chunkhash].js',
publicPath: 'http://cdn.com/'
},
plugins: [
new htmlWebpackPlugin({
filename: 'a.html',
template: 'index.html',
inject: 'body',
title: 'this is a',
excludeChunks: ['b', 'c'] //不包括的chunks
}),
new htmlWebpackPlugin({
filename: 'b.html',
template: 'index.html',
inject: 'body',
title: 'this is b',
excludeChunks: ['a', 'c']
}),
new htmlWebpackPlugin({
filename: 'c.html',
template: 'index.html',
inject: 'body',
title: 'this is c',
excludeChunks: ['a', 'b']
})
]
};

4 根目录模板 index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= htmlWebpackPlugin.options.title %></title>
<!--将mian.js写在页面里面
去掉不带publicPath的内容如 http://cdn.cn/
compilation.assets[].source()
-->
<script type="text/javascript">
<%= compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source() %>
</script>
</head>
<body> <!--如果chunk有main.js就不引入 因为上面引入了??????-->
<% for(var key in htmlWebpackPlugin.files.chunks){ %>
<% if(key !== 'main'){ %>
<script type="text/javascript" src="<%= htmlWebpackPlugin.files.chunks.entry %>"></script>
<% } %>
<% } %>
</body>
</html>

5 打包

6 查看变化

6.1 a.html

6.2 b.html

6.3 c.html

最新文章

  1. linux设置定时备份mysql数据库
  2. sharepoint报HRESULT:0x80131904的错误的原因和解决方法
  3. 从零自学Hadoop(12):Hadoop命令中
  4. python 多态
  5. Linux(10.18-10.25)学习笔记
  6. PHP中的错误处理和异常处理
  7. 关于Switch结构利用
  8. HDU 3062 Party
  9. HDU 4496 D-City(并查集,逆思维)
  10. WC约束示使用
  11. iOS UILabel:宽度固定,自动高度显示全部文字
  12. javascript创建对象(二)
  13. openresty nginx 安装过程记录
  14. 查看堵塞的SQL
  15. VS生成时复制文件到指定目录
  16. mysql笔记一——安装和设置root密码
  17. BZOJ4554 - [TJOI2016&HEOI2016]游戏
  18. hdu 3478 Catch--二分图判断
  19. js查重去重性能优化心得
  20. VS开发入门三:c#的类的修饰符和成员的修饰符

热门文章

  1. Python 学习系列----第一章:基础知识
  2. setAttribute设置无效
  3. 【&#9733;】RSA-什么是不对称加密算法?
  4. 转:【Java并发编程】之九:死锁(含代码)
  5. SNS团队第七次站立会议(2017.04.28)
  6. 团队作业10——复审和事后分析(Beta版本)
  7. 【Beta】Daily Scrum Meeting——Day4
  8. Swing-BoxLayout用法-入门
  9. 201521123045 《Java程序设计》第6周学习总结
  10. 201521123012 《Java程序设计》第六周学习总结