npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-plugin-svgr

v3.0.0-beta.0

Published

SVGR plugin for Gatsby

Downloads

46,217

Readme

gatsby-plugin-svgr npm version

SVGR plugin for Gatsby v2.0+. Still rocking Gatsby v1? See the v1 branch instead.

Installing

As of v2.0, SVGR is declared as a peer dependency. You will need to add gatsby-plugin-svgr as well as @svgr/webpack to your dependencies.

$ npm install @svgr/webpack gatsby-plugin-svgr

or

$ yarn add @svgr/webpack gatsby-plugin-svgr

Setup

Add it to your gatsby-config.js

module.exports = {
  plugins: [
    'gatsby-plugin-svgr',
  ],
}

Options

Note: If you need to configure SVGO, we recommended this approach instead of the below. Documentation update to follow.

Any options you configure gatsby-plugin-svgr with will be passed on to svgr with the exception of include and exclude (see below). You can see a full list of SVGR options here (you want the API override version). SVGR uses SVGO to optimize SVGs; you can configure SVGO using svgoConfig; see SVGO for a full list of configuration options.

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-svgr',
      options: {
        prettier: true,          // use prettier to format JS code output (default)
        svgo: true,              // use svgo to optimize SVGs (default)
        svgoConfig: {
          plugins: [
            { removeViewBox: true }, // remove viewBox when possible (default)
            { cleanupIDs: true },    // remove unused IDs and minify remaining IDs (default)
          ],
        },
      },
    },
  ],
}

Note: SVGO does not produce unique IDs when using the cleanupIDs option; if you're using SVGs that rely on IDs (e.g. to target template elements with use) and include multiple SVGs on the same page you may wish to disable the cleanupIDs option to prevent conflicts. Alternately you can disable svgo altogether and perform any optimization either manually or through another build process.

Applying SVGR to only some resources

By default, SVGR is only used to load resources when loaded via JS (i.e. your stylesheets will fallback to the default loader). If you only want to apply SVGR to some resources, or you want to exclude some resources, you can pass include or exclude as options. These are passed directly to the SVGR loader as Conditions.

{
  resolve: 'gatsby-plugin-svgr',
  options: {
    exclude: /some_special_folder/,
  },
}

Usage

import starUrl, { ReactComponent as Star } from './star.svg'

const App = () => (
  <div>
    <img src={starUrl} alt="star" />
    <Star />
  </div>
)