Giter Site home page Giter Site logo

dios-david / svg-spritemap-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cascornelissen/svg-spritemap-webpack-plugin

0.0 1.0 0.0 2.34 MB

SVG spritemap plugin for webpack

License: MIT License

JavaScript 89.88% CSS 0.42% Less 0.63% SCSS 9.07%

svg-spritemap-webpack-plugin's Introduction

SVG Spritemap Webpack Plugin

npm npm codevov license

This webpack plugin generates a single SVG spritemap containing multiple <symbol> elements from all .svg files in a directory. In addition, it can optimize the output and can also generate a stylesheet containing the sprites to be used directly from CSS. Chris Coyier has a good write-up about the why's and how's of this technique on CSS Tricks. Use it in combination with the svg4everybody package to easily and correctly load SVGs from the spritemap in all browsers.

Installation

npm install svg-spritemap-webpack-plugin --save-dev

Usage

Webpack configuration
This plugin can be added to webpack like any other, documentation on all configuration options is available.

const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin');

module.exports = {
    // ...
    plugins: [
        new SVGSpritemapPlugin()
    ]
}

SVG element
When there's a file phone.svg in the source directory and the prefix option is set to sprite- (default), the sprite can be included in a HTML-file like so:

<svg>
    <use xlink:href="/path/to/spritemap.svg#sprite-phone"></use>
</svg>

SVG4Everybody

SVG for Everybody adds SVG External Content support to all browsers.

It's a good idea to combine the svg-spritemap-webpack-plugin with svg4everybody. This can be done by passing an options object or true to the svg4everybody options key or by executing SVG4Everybody manually.

License

This project is licensed under the MIT license.

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.