如何添加 favicon gatsby-config.js?

set*_*wan 7 gatsby

所以我尝试在我的博客中添加网站图标,代码如下:在我的 gatsby-config.js 中

module.exports = {
  siteMetadata: {
    title: 'Chatbiz Blog',
  },
  plugins: [
    'gatsby-plugin-react-helmet',
    'gatsby-plugin-catch-links',
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        path: `${__dirname}/src/pages`,
        name: 'pages',
        icon: `https://blablabla/favicon.ico`
      },
    },
    'gatsby-transformer-remark',
  ],
}
Run Code Online (Sandbox Code Playgroud)

所以问题是当我尝试这段代码时,网站图标无法在我的博客中呈现如何解决问题?

小智 15

我相信,您将图标参数放在错误的包选项中。

要解决这个问题,首先使用以下命令安装 gatsby manifest 插件:

npm install --save gatsby-plugin-manifest
Run Code Online (Sandbox Code Playgroud)

然后将其添加到 gatsby-config.js 中:

{
  resolve: `gatsby-plugin-manifest`,
  options: {
    name: `gatsby-starter-default`,
    short_name: `starter`,
    start_url: `/`,
    background_color: `#663399`,
    theme_color: `#663399`,
    display: `minimal-ui`,
    icon: `src/images/favicon.png`, // This path is relative to the root of the site.
  },
Run Code Online (Sandbox Code Playgroud)

请记住停止并启动您的开发服务器以查看您的更改。