130.在output中配置publicPath项,修改webpack.config.js文件,代码如下
var htmlWebpackPlugin = require("html-webpack-plugin"); module.exports = { entry:{ main:'./src/script/main.js', a:'./src/script/a.js' }, output:{ path:'./dist', filename:'js/[name]-[hash].js', publicPath:'http://cdn.com/' }, plugins:[ new htmlWebpackPlugin({ template:'index.html', filename:'a.html', inject:false, title:'this is a.html' }), new htmlWebpackPlugin({ template:'index.html', filename:'b.html', inject:false, title:'this is b.html' }), new htmlWebpackPlugin({ template:'index.html', filename:'c.html', inject:false, title:'this is c.html' }) ] }
131.在模板文件index.html中使用publicPath以及在有publicPath时不用的情况
htmlWebpackPlugin.files.chunks.main.entry.substr(htmlWebpackPlugin.files.publicPath.length) htmlWebpackPlugin.files.chunks.main.entry
131.使用cnpm run webpack命令重新打包
132.查看生成的a.html,b.html,c.html文件
本文转自 素颜猪 51CTO博客,原文链接:http://blog.51cto.com/suyanzhu/1899609