webpack打包多个html文件 javascript
plugins:[
new htmlWebpackPlugin({
filename:'index111.html', //输出后的html文件
template:'index.html',
inject:'body',
title:'safsdf',
data:'SDFDSF',
chunks:['main1']
}),
new htmlWebpackPlugin({
filename:'index222.html', //输出后的html文件
template:'index.html',
inject:'body',
title:'safsdf',
data:'SDFDSF',
chunks:['main2'] //页面中所须要的js
})
]
须要注意的是,若是index页面中加载了js的话,只有第一个文件能够打包好 ,其余会报错html
若是页面中入加载的js不少 那么能够用另外一个属性excludeChunks:['a'] 排除a文件 加载其余全部文件java
//能够吧公共的js放入内联加载webpack
<script type="text/javascript"> <%=compilation.assets[htmlWebpackPlugin.files.chunks.main1.entry.substr(htmlWebpackPlugin.files.publicPath.length)].source()%> </script>
<% for (var k in htmlWebpackPlugin.files.chunks){%> <% if (k!== "main1"){ %> <script type="text/javascript" src="<%=htmlWebpackPlugin.files.chunks[k].entry%>"</script> <%}%> <%}%>