Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including svg-spritemap-webpack-plugin with all npm packages installed. Try it out:

require("webpack/package.json"); // webpack is a peer dependency. var svgSpritemapWebpackPlugin = require("svg-spritemap-webpack-plugin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

svg-spritemap-webpack-plugin v3.5.6

Generates symbol-based SVG spritemap from all .svg files in a directory

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.

Compatibility
Version ^2.0.0 of this plugin is compatible with webpack ^4.0.0. When using an older version of webpack, make sure to install the ^1.0.0 (svg-spritemap-webpack-plugin@^1.0.0) release of this plugin.

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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free