108.在htmlWebpackPlugin中使用date,修改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'
	},
	plugins:[
		new htmlWebpackPlugin({
			template:'index.html',
			filename:'index-[hash].html',
			inject:'head',
			date:new Date()
		})
	]
}

109.安装html-webpack-plugin插件

cnpm install html-webpack-plugin --save-dev

Webpack入门教程二十二

110.修改模板文件index.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>webpack demo</title>
	<link rel="stylesheet" href="">
</head>
<body>
	<%= htmlWebpackPlugin.options.date %>
</body>
</html>

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

Webpack入门教程二十二



本文转自 素颜猪 51CTO博客,原文链接:http://blog.51cto.com/suyanzhu/1899515

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-12-13
  • 2021-05-07
  • 2021-12-01
  • 2021-04-26
  • 2021-05-03
  • 2021-09-15
猜你喜欢
  • 2021-08-25
  • 2021-05-29
  • 2021-08-09
  • 2021-04-22
  • 2021-12-25
  • 2021-11-03
  • 2021-07-30
相关资源
相似解决方案