Tuesday, March 15, 2016

Webpack html-webpack-plugin load favicons in template

Leave a Comment

I'm using Webpack with html-webpack-plugin and their provided template. I want to add a list of favicons in the header:

<link rel="apple-touch-icon" sizes="57x57" href="<%= htmlWebpackPlugin.extraFiles.apple-touch-icon-57x57 %>"> <link rel="apple-touch-icon" sizes="60x60" href="<%= htmlWebpackPlugin.extraFiles.favicons.fav60%>"> <link rel="apple-touch-icon" sizes="72x72" href="<%= htmlWebpackPlugin.extraFiles.favicons.fav72%>"> <link rel="apple-touch-icon" sizes="76x76" href="favicons/apple-touch-icon-76x76.png"> <link rel="apple-touch-icon" sizes="114x114" href="favicons/apple-touch-icon-114x114.png"> <link rel="apple-touch-icon" sizes="120x120" href="favicons/apple-touch-icon-120x120.png"> <link rel="apple-touch-icon" sizes="144x144" href="favicons/apple-touch-icon-144x144.png"> <link rel="apple-touch-icon" sizes="152x152" href="favicons/apple-touch-icon-152x152.png"> <link rel="apple-touch-icon" sizes="180x180" href="favicons/apple-touch-icon-180x180.png"> <link rel="icon" type="image/png" href="favicons/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="favicons/android-chrome-192x192.png" sizes="192x192"> <link rel="icon" type="image/png" href="favicons/favicon-96x96.png" sizes="96x96"> <link rel="icon" type="image/png" href="favicons/favicon-16x16.png" sizes="16x16"> <link rel="manifest" href="favicons/manifest.json"> <link rel="mask-icon" href="favicons/safari-pinned-tab.svg" color="#e53935"> <meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-TileImage" content="favicon/mstile-144x144.png"> <meta name="theme-color" content="#e53935"> 

How can I include all the favicons in my webpack build, with or without html-webpack-plugin?

I tried adding them as extraFiles like the docs say, but they don't end up in my build folder.

Note: The first 3 was me trying to something that didn't work.

1 Answers

Answers 1

After numerous trials...still didn't manage to make it work with html-webpack-plugin, I did find a new library that helps with everything relating to titles, descriptions, keywords,...and almost any kind of header called react-helmet

You can find it here: https://github.com/nfl/react-helmet

Basically you add something like this in your main component

<Helmet     link={[         {"rel": "apple-touch-icon", "href": require('apple-touch-icon-57x57.png'), "sizes": "57x57}      ]}  /> 

Hope this helps others.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment