美文网首页
vue 2.0项目 favicon.ico不显示 解决方案

vue 2.0项目 favicon.ico不显示 解决方案

作者: 缪先生_ | 来源:发表于2020-01-11 17:37 被阅读0次

1.最好把图标与index.html放入同一级

2.在build文件夹下webpack 配置文件里面配置

// 在webpack.dev.conf.js 里面的 plugins配置

new HtmlWebpackPlugin({
  filename: 'index.html',
  template: 'index.html',
  inject: true,
  favicon: './favicon.ico'      //增加这条
})

//在 webpack.prod.conf.js 里面 plugins 配置 ,不然build的时候也找不到favicon.ico

new HtmlWebpackPlugin({
  filename: config.build.index,
  template: 'index.html',
  inject: true,
  favicon: './favicon.ico',        //增加这条
  minify: {
    removeComments: true,
    collapseWhitespace: true,
    removeAttributeQuotes: true
  },
  chunksSortMode: 'dependency'
})

3.在index.html中上一行复制以下代码

<link rel="shortcut icon" type="image/x-icon" href="./favicon.ico" />

4.重启项目就OK了

查看来源

相关文章

网友评论

      本文标题:vue 2.0项目 favicon.ico不显示 解决方案

      本文链接:https://www.haomeiwen.com/subject/hclbactx.html