码迷,mamicode.com
首页 > Web开发 > 详细

Webpack入门教程二十九

时间:2017-02-20 23:18:16      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:webpack入门教程十九二十九

133.在模板中以内联的形式引用script脚本,修改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‘
		})
	]
}

134.修改模板文件index.html,代码如下

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title><%= htmlWebpackPlugin.options.title %></title>
	<link rel="stylesheet" href="">
	<script type="text/javascript">
			<%= compilation.assets[htmlWebpackPlugin.files.chunks.main.entry.substr(html
			WebpackPlugin.files.publicPath.length)].source() %>
	</script>
</head>
<body>
</body>
</html>

技术分享

135.使用cnpm run webpack命令重新打包

技术分享

136.查看生成的a.html,b.html,c.html文件

技术分享


技术分享


技术分享



Webpack入门教程二十九

标签:webpack入门教程十九二十九

原文地址:http://suyanzhu.blog.51cto.com/8050189/1899612

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!