Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue index.html favicon issue

I am using Vue 2.0 and Vue CLI 3.0. I am trying to get the favicon.ico/png file work properly and am having no luck at all.

I have narrowed the issue to the following.

The index.html file generated by yarn build converts this line of html code:

<link rel="icon" href="favicon.png" >

to...

<!--[if IE]><link rel="icon" href="favicon.png"><![endif]-->

If I go into Chrome developer tools and change the line back to the way I had it originally, the ico/png file renders as expected.

My question is: how do I fix this so that yarn build stops messing up my html code.

like image 378
Bill Haack Avatar asked Oct 07 '18 01:10

Bill Haack


People also ask

Why favicon is not working in HTML?

When you add a favicon to your site, it may not show up since your browser has 'saved' your site as one without a favicon. You need to clear the cache in your browser or use a different browser.

How do I add favicon to Vue?

Just generate a . ico favicon file (this site provides free online favicon generation), rename it to favicon. ico and place it in public folder, no need to change index. html , reload and new favicon will be displayed.

What size should a favicon be 2022?

The standard size for favicons is 16x16 pixels, but most designers start with 32x32 pixels to accommodate retina screens. This way, the larger favicons show up nicely on retina screens and can also be scaled down.

What is index HTML in Vue?

The Index File html is a template that will be processed with html-webpack-plugin. During build, asset links will be injected automatically.


1 Answers

Inside the vue.config.js set the PWA options for the icons to point to whatever icons you want. Specifically, set pwa.iconPaths for example:

module.exports = {
  pwa: {
    iconPaths: {
       favicon32: 'img/icons/myFavicon.png',
    }
  }
}

See

  • https://cli.vuejs.org/config/#pwa
  • https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
like image 52
Justin Kahn Avatar answered Oct 26 '22 09:10

Justin Kahn