gatsby image svg not found

后端 未结 4 1597
面向向阳花
面向向阳花 2021-02-14 07:05

When trying to load an SVG image this way:

export const query = graphql`
    query {
        fileName: file(relativePath: { eq: \"logo_large.svg\" }) {
                  


        
4条回答
  •  不要未来只要你来
    2021-02-14 07:38

    "SVG are not supported by this plugin for obvious reasons, they are vectorial and automatically adjust their size without the need of plugin like this one"

    Correct. If you want to handle multiple types like png + jpg + svg you have to dynamically handle it with gatsby-image or not. You solve this by adding extension and publicURL in your GraphQL query:

      ...
      image {
        childImageSharp {
          fluid(maxWidth: 500, quality: 92) {
            ...GatsbyImageSharpFluid
          }
        }
        extension
        publicURL
      }
      ...
    

    Add this to your image component:

      // svg support
      if (!childImageSharp && extension === 'svg') {
        return {alt}
      }
    

    Credit goes to andresmrm on GitHub.

提交回复
热议问题