Webpack html-webpack-plugin 在模板中加载网站图标 [英] Webpack html-webpack-plugin load favicons in template

查看:26
本文介绍了Webpack html-webpack-plugin 在模板中加载网站图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Webpack 与 html-webpack-plugin 及其提供的模板一起使用.我想在标题中添加一个收藏夹图标列表:

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">

如何在我的 webpack 构建中包含所有网站图标,无论有没有 html-webpack-plugin?

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

我尝试像文档所说的那样将它们添加为 extraFiles,但它们最终没有出现在我的构建文件夹中.

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

注意:前 3 个是我尝试了一些没有用的东西.

推荐答案

经过无数次尝试...仍然没有设法让它与 html-webpack-plugin 一起工作,我确实找到了一个新库可帮助处理与标题、描述、关键字以及几乎任何类型的名为 react-helmet

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

您可以在这里找到它:https://github.com/nfl/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.

这篇关于Webpack html-webpack-plugin 在模板中加载网站图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆