vue打包加版本號

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
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章