vue 項目線上環境 出現 favicon.ico 不顯示 怎麼辦?
一直提示報錯: GET HTTP: xxx.xxxx.xxx.xxx:8080/favicon.ico 404 (Not Found);總之是沒找到這個文件;
一打包之後,favicon.ico 這個文件就不見了,問題肯定出現在webpack輸出配置中;
所以從兩方面入手:
第一步: 修改webpack配置;
同時在 webpack.dev.conf.js 和 webpack.prod.conf.js 中同時添加 favicon: './favicon.ico';
如果你的相關配置是在 utils.js 中 那麼改一次就行了;
// 在 plugins配置
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: './favicon.ico' //增加這條
})
第二步: 修改index.html;
在header中添加,要注意 favicon.ico 的路徑 不要寫錯了;
<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />
至此,發版,強刷,大功告成;