I need to use an inline SVG so I can animate it, but the SVG is less than 10KB so Gatsby is converting it to a data-uri. Is there a way to tell Gatsby to not convert a particular resource to a data-uri?
As you pointed out, there's no GatsbyImageData because Gatsby's transformers and sharps ( gatsby-transformer-sharp but especially gatsby-plugin-sharp ) doesn't support SVG. As they are not able to interpret SVG assets, they are not able to create the GraphQL nodes.
This you can use as src of img tag. And this method: import { ReactComponent as Img } from 'path/to/file. svg' allows you to import inline svg.
You can use gatsby-plugin-react-svg
.
npm install --save gatsby-plugin-react-svg
Add the plugin to your gatsby-config.js
, then in your code:
import Icon from './path/icon.svg';
// ...
<Icon />
Alternatively, you can also use gatsby-plugin-svgr
.
To add to Fabian Schultz's answer
There is Gatsby v2 support for gatsby-plugin-react-svg if you use the @next version
npm install gatsby-plugin-react-svg@next --save
There were 2 tickets opened in the repo
Issue 4
Issue 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With