基於vue-cli 2
首先將favicon.ico圖片放在根目錄下,通過以下兩種方法使其顯示正確。
方法一:修改index.html文件
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
缺點:打包后需要將favicon.ico復制到根目錄
方法二:修改webpack配置文件
1、找到build下的webpack.dev.conf.js文件
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico') // 新增
}),
2、找到build下的webpack.prod.conf.js文件
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
favicon: path.resolve('favicon.ico'), //新增
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
...
}),
修改配置文件后需重啟npm run dev
打包后根目錄下就會有favicon.ico
