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

Inline and optimize SVG's from your GraphQL data source

License

Notifications You must be signed in to change notification settings

paulkre/gatsby-transformer-svg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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 }} />
    );
  }
}

About

Inline and optimize SVG's from your GraphQL data source

Resources

License

Stars

Watchers

Forks

Packages

No packages published