1、引入html-webpack-plugin,html-webpack-plugin详解参考:https://www.cnblogs.com/wonyun/p/6030090.html
npm install --save-dev html-webpack-plugin
2、在webpack.prod.conf.js的plugin中新增配置

const date = new Date();
const timestamp = date.getTime(); // 时间戳

new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
time: moment(date).format('YYYY-MM-DD HH:mm:ss.SSS'),
timestamp: timestamp,
favicon: resolve('icon.ico'), // 图标
title: 'xxxx公司', // 标题
minify: {
removeComments: true, // 打包后删除注释
collapseWhitespace: true, // 打包后删除空格
removeEmptyAttributes: true, // 打包后删除空属性
removeAttributeQuotes: true // 打包后删除引号
},
cdn: {
css: [
'/static/icon/iconfont.min.css',
'/static/lib/css/element-ui/index.min.css',
'/static/lib/css/buttons/buttons.min.css',
'/static/lib/css/print-js/print.min.css'
],
js: [
'/static/lib/js/babel-polyfill/browser-polyfill.js'
]
}
})
在index.html中使用:

<!-- require cdn assets css -->
<% for (var i in htmlWebpackPlugin.options.cdn && htmlWebpackPlugin.options.cdn.css) { %>
<link rel='stylesheet' href='<%= htmlWebpackPlugin.options.cdn.css[i] %>' />
<% } %>
<script src="/static/config/index.js?_t=<%=new Date().valueOf()%>"></script>
<script src="/static/expand/index.js"></script>
<!-- require cdn assets js -->
<% for (var i in htmlWebpackPlugin.options.cdn && htmlWebpackPlugin.options.cdn.js) { %>
<script type='text/javascript' src='<%= htmlWebpackPlugin.options.cdn.js[i] %>'></script>
<% } %>

1027

被折叠的 条评论
为什么被折叠?



