解決 vue-cli 打包後圖片路徑獲取不到的問題
阿新 • • 發佈:2020-10-16
摘抄部落格:vue-cli打包後圖片路徑取不到的問題
1. 第一步
在config / index.js
檔案中把assetsPublicPath
修改為 ./
2. 第二步
在 build / webpack.prod.conf.js
檔案中,在output
裡增加 publicPath: './'
3. 第三步
雖然解決了資源路徑的引用問題,但是資源裡面的背景圖片還是不顯示, background: url("../../assets/images/logo-index.png") no-repeat;
被相對打包後變成了url(static/img/logo-index.2fbf2.png) no-repeat
url(../../static/img/logo-index.2fbf2.png) no-repeat
那麼就需要修改build / utils.js
檔案裡新增publicPath: '../../'