GithubHelp home page GithubHelp logo

first10 / gatsby-plugin-svg-sprite-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stldo/gatsby-plugin-svg-sprites

0.0 1.0 0.0 65 KB

Gatsby plugin for creating SVG sprites using SVG sprite loader

License: MIT License

JavaScript 100.00%

gatsby-plugin-svg-sprite-loader's Introduction

gatsby-plugin-svg-sprite-loader

Gatsby plugin for creating SVG sprites using SVG sprite loader.

Install

$ npm install gatsby-plugin-svg-sprite-loader

Configure

// gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-svg-sprite-loader`,
      options: {
        /* SVG sprite loader options */
        pluginOptions: {
          /* SVG sprite loader plugin options */
        }
      },
    },
  ],
}

options

The options parameter is passed directly to SVG sprite loader, the documentation can be found on SVG sprite loader documentation. By default, this plugin sets extract option to true, spriteFilename to 'sprites.[contenthash].svg' and symbolId to '[name]--[hash:base64:5]' — the naming convention is the same used by Gatsby for CSS files.

pluginOptions

The pluginOptions parameter is passed to svg-sprite-loader/plugin — if extract is set to true in the options parameter. If the images are being defined only inside <use xlinkHref='...'/> — and never inside CSS or <img> elements — set plainSprite option to true, so SVG sprite loader will generate a lighter output file.

Usage

If extract mode is enabled (set to true by default), use sprite.url in xlinkHref prop. Otherwise, use sprite.id.

/* extract === true (default) */
import React from 'react'
import sprite from 'images/sprite.svg'

export default () => (
  <svg viewBox={sprite.viewBox}>
    <use xlinkHref={sprite.url}/>
  </svg>
)
/* extract === false */
import React from 'react'
import sprite from 'images/sprite.svg'

export default () => (
  <svg viewBox={sprite.viewBox}>
    <use xlinkHref={sprite.id}/>
  </svg>
)

License

The MIT License

gatsby-plugin-svg-sprite-loader's People

Contributors

stldo avatar tomwalsh-home avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.