Inline and optimize SVG's from your GraphQL data source
yarn add @paulkre/gatsby-transformer-svg
module.exports = {
plugins: ["@paulkre/gatsby-transformer-svg"],
};
Optionally, you can also override the SVGO options which are being used internally to optimize the .svg
files:
module.exports = {
plugins: [
{
resolve: "@paulkre/gatsby-transformer-svg",
options: {
svgo: {
multipass: true,
floatPrecision: 2,
plugins: [
// ...
],
},
},
},
],
};
file {
childSvg {
content {
data
width
height
}
}
}
import React from "react";
export default function Image({ file }) {
if (file?.childSvg?.content) {
return (
<div dangerouslySetInnerHTML={{ __html: file?.childSvg?.content.data }} />
);
}
}