Vue打包文件放在服务器,浏览器存在缓存问题的解决

在入口文件index.html添加

<meta http-equiv="pragram" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="expires" content="0">

 

因浏览器缓存原因导致vue 打包后的文件不能即使更新最新代码。缓存里的内容没有清除。(基本没作用)

解决办法就是在打包的文件名中添加一个版本号以便浏览器能区分。

 

build--webpack .prod.conf.js

const  Version = new Date().getTime(); //定义一个时间作为版本号。

 output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].[chunkhash]'+ Version+'.js'),
    chunkFilename: utils.assetsPath('js/[id].[chunkhash]'+Version +'.js')
  }

posted @ 2019-05-21 11:36  奶包迷了鹿  阅读(2461)  评论(0)    收藏  举报