Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Latest commit

 

History

History
68 lines (55 loc) · 1.04 KB

README.md

File metadata and controls

68 lines (55 loc) · 1.04 KB

@paulkre/gatsby-transformer-svg

Inline and optimize SVG's from your GraphQL data source

Installation

yarn add @paulkre/gatsby-transformer-svg

Usage

gatsby-config.js

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: [
            // ...
          ],
        },
      },
    },
  ],
};

GraphQL Query

file {
  childSvg {
    content {
      data
      width
      height
    }
  }
}

Rendering

import React from "react";

export default function Image({ file }) {
  if (file?.childSvg?.content) {
    return (
      <div dangerouslySetInnerHTML={{ __html: file?.childSvg?.content.data }} />
    );
  }
}