為了實(shí)現(xiàn)項(xiàng)目上傳后不存在緩存問(wèn)題,需要在webpack中加上配置信息
在項(xiàng)目根目錄中添加vue.config.js文件
const Timestamp = new Date().getTime();
module.exports = {
// webpack配置
chainWebpack: config => {
if (process.env.NODE_ENV === 'production') {
// 給js和css配置版本號(hào)
config.output.filename('js/[name].' + Timestamp + '.js').end();
config.output.chunkFilename('js/[name].' + Timestamp + '.js').end();
config.plugin('extract-css').tap(args => [{
filename: `css/[name].${Timestamp}.css`,
chunkFilename: `css/[name].${Timestamp}.css`
}])
}
},
css: {
loaderOptions: {
sass: {
// 向全局sass樣式傳入共享的全局變量
data: `@import "@/styles/public.scss";@import "@/styles/element_ui_style.scss";`
}
}
},
lintOnSave: false,
productionSourceMap: true,
//是開發(fā)模式的時(shí)候,獲取當(dāng)前路徑下的地址,是測(cè)試或者開發(fā)模式的時(shí)候,用/獲取地址
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
}
或者
// vue.config.js
const Timestamp = new Date().getTime();
module.exports = {
configureWebpack: { // webpack 配置
output: { // 輸出重構(gòu) 打包編譯后的 文件名稱 【模塊名稱.版本號(hào).時(shí)間戳】
filename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`,
chunkFilename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`
},
},
...
}
js、css加版本號(hào)參考:https://blog.csdn.net/superKM/article/details/102471167?biz_id=102