vue打包會用隨機字符串作爲文件名,控制靜態資源及時更新,但是有些時候,瀏覽器就是不更新,可以在引入靜態資源後面再添加版本號。
vue-cli 2.0
修改build/webpack.prod.conf.js,在HtmlWebpackPlugin插件配置項中添加hash: true
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: true,
hash: true, // 添加改選項
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
},
chunksSortMode: 'dependency'
})
vue-cli 3.0
修改vue.config.js,沒有該文件則手動添加
module.exports = {
filenameHashing: true
}