Coder Social home page Coder Social logo

jetbrains / svg-sprite-loader Goto Github PK

View Code? Open in Web Editor NEW
2.0K 48.0 272.0 1.8 MB

Webpack loader for creating SVG sprites.

License: MIT License

JavaScript 98.53% SCSS 0.20% Shell 1.27%
svg svg-sprite svg-stack webpack webpack2 webpack3 webpack-loader webpack-plugin sprite

svg-sprite-loader's Introduction

obsolete JetBrains project

SVG sprite loader

NPM version Build status Documentation score Dependencies status Dev dependencies status NPM downloads

Webpack loader for creating SVG sprites.

๐ŸŽ‰ 2.0 is out, please read the migration guide & overview.

โš ๏ธ For old v0.x versions see the README in the v0 branch.

Table of contents

Why it's cool

  • Minimum initial configuration. Most of the options are configured automatically.
  • Runtime for browser. Sprites are rendered and injected in pages automatically, you just refer to images via <svg><use xlink:href="#id"></use></svg>.
  • Isomorphic runtime for node/browser. Can render sprites on server or in browser manually.
  • Customizable. Write/extend runtime module to implement custom sprite behaviour. Write/extend runtime generator to produce your own runtime, e.g. React component configured with imported symbol.
  • External sprite file is generated for images imported from css/scss/sass/less/styl/html (SVG stacking technique).

Installation

npm install svg-sprite-loader -D
# via yarn
yarn add svg-sprite-loader -D

Configuration

// webpack 1
{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  query: { ... }
}

// webpack 1 multiple loaders
{
  test: /\.svg$/,
  loaders: [
    `svg-sprite-loader?${JSON.stringify({ ... })}`,
    'svg-transform-loader',
    'svgo-loader'
  ]
}

// webpack >= 2
{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: { ... }
}

// webpack >= 2 multiple loaders
{
  test: /\.svg$/,
  use: [
    { loader: 'svg-sprite-loader', options: { ... } },
    'svg-transform-loader',
    'svgo-loader'
  ]
}

symbolId (string | function(path, query), default [name])

How <symbol> id attribute should be named. All patterns from loader-utils#interpolateName are supported. Also can be a function which accepts 2 args - file path and query string and return symbol id:

{
  symbolId: filePath => path.basename(filePath)
}

symbolRegExp (default '')

Passed to the symbolId interpolator to support the [N] pattern in the loader-utils name interpolator

esModule (default true, autoconfigured)

Generated export format:

  • when true loader will produce export default ....
  • when false the result is module.exports = ....

By default depends on used webpack version: true for webpack >= 2, false otherwise.

Runtime configuration

When you require an image, loader transforms it to SVG <symbol>, adds it to the special sprite storage and returns class instance that represents symbol. It contains id, viewBox and content (id, viewBox and url in extract mode) fields and can later be used for referencing the sprite image, e.g:

import twitterLogo from './logos/twitter.svg';
// twitterLogo === SpriteSymbol<id: string, viewBox: string, content: string>
// Extract mode: SpriteSymbol<id: string, viewBox: string, url: string, toString: Function>

const rendered = `
<svg viewBox="${twitterLogo.viewBox}">
  <use xlink:href="#${twitterLogo.id}" />
</svg>`;

When browser event DOMContentLoaded is fired, sprite will be automatically rendered and injected in the document.body. If custom behaviour is needed (e.g. a different mounting target) default sprite module could be overridden via spriteModule option. Check example below.

spriteModule (autoconfigured)

Path to sprite module that will be compiled and executed at runtime. By default it depends on target webpack config option:

  • svg-sprite-loader/runtime/browser-sprite.build for 'web' target.
  • svg-sprite-loader/runtime/sprite.build for other targets.

If you need custom behavior, use this option to specify a path of your sprite implementation module. Path will be resolved relative to the current webpack build folder, e.g. utils/sprite.js placed in current project dir should be written as ./utils/sprite.

Example of sprite with custom mounting target (copypasted from browser-sprite):

import BrowserSprite from 'svg-baker-runtime/src/browser-sprite';
import domready from 'domready';

const sprite = new BrowserSprite();
domready(() => sprite.mount('#my-custom-mounting-target'));

export default sprite; // don't forget to export!

It's highly recommended to extend default sprite classes:

symbolModule (autoconfigured)

Same as spriteModule, but for sprite symbol. By default also depends on target webpack config option:

  • svg-baker-runtime/browser-symbol for 'web' target.
  • svg-baker-runtime/symbol for other targets.

runtimeGenerator (default generator)

Path to node.js script that generates client runtime. Use this option if you need to produce your own runtime, e.g. React component configured with imported symbol. Example.

runtimeCompat (default false, deprecated)

Should runtime be compatible with earlier v0.x loader versions. This option will be removed in the next major version release.

runtimeOptions

Arbitrary data passed to runtime generator. Reserved for future use when other runtime generators will be created.

Extract configuration

In the extract mode loader should be configured with plugin, otherwise an error is thrown. Example:

// webpack.config.js
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');

...

{
  plugins: [
    new SpriteLoaderPlugin()
  ]
}

extract (default false, autoconfigured)

Switches loader to the extract mode. Enabled automatically for images imported from css/scss/sass/less/styl/html files.

spriteFilename (type string|Function<string>,default sprite.svg)

Filename of extracted sprite. Multiple sprites can be generated by specifying different loader rules restricted with include option or by providing custom function which recieves SVG file absolute path, e.g.:

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    spriteFilename: svgPath => `sprite${svgPath.substr(-4)}`
  }
}

[hash] in sprite filename will be replaced by it's content hash. It is also possible to generate sprite for each chunk by using [chunkname] pattern in spriteFilename option. This is experimental feature, use it with caution!

publicPath (type: string, default: __webpack_public_path__)

Custom public path for sprite file.

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    publicPath: '/'
  }
}

outputPath (type: string, default: null`)

Custom output path for sprite file. By default it will use publicPath. This param is useful if you want to store sprite is a directory with a custom http access.

{
  test: /\.svg$/,
  loader: 'svg-sprite-loader',
  options: {
    extract: true,
    outputPath: 'custom-dir/sprites/'
    publicPath: 'sprites/'
  }
}

Plain sprite

You can render plain sprite in extract mode without styles and usages. Pass plainSprite: true option to plugin constructor:

{
  plugins: [
    new SpriteLoaderPlugin({ plainSprite: true })
  ]
}

Sprite attributes

Sprite <svg> tag attributes can be specified via spriteAttrs plugin option:

{
  plugins: [
    new SpriteLoaderPlugin({
      plainSprite: true,
      spriteAttrs: {
        id: 'my-custom-sprite-id'
      }
    })
  ]
}

Examples

See examples folder.

Contributing guidelines

See CONTRIBUTING.md.

License

See LICENSE

Credits

Huge thanks for all this people.

svg-sprite-loader's People

Contributors

andrey-skl avatar cxhtml avatar dependabot[bot] avatar ekaterinamusienko avatar fr-ench avatar freelance-tech-writer avatar ghostd avatar huang-x-h avatar ihmels avatar iqingting avatar joearasin avatar kisenka avatar maksimr avatar mayako21126 avatar meowtec avatar nielsjanssen avatar princed avatar protango avatar rajdee avatar rgiese avatar roamn avatar rocking42 avatar ryanclark avatar sg-4xxi avatar slashgear avatar steplov avatar wanecek avatar wmertens avatar xinhailishi avatar zaycker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svg-sprite-loader's Issues

SVG rendering incorrectly

Hi there,

I've been debugging this issue for a while and I'm having trouble tracking down the issue.

An SVG I'm loading in React using this library is not rendering correctly.

It looks like:

screenshot 2016-09-14 17 01 17

But it should look like:

screenshot 2016-09-14 17 03 31

Both of those screen shots are rendered in Chrome. The first one is using this library with the prescribed React method. The second one, I use raw-loader and dangerouslySetInnerHtml on an element and it works.

Does anyone know what might be causing this?

Are there any optimization steps that I can turn off that might be corrupting the image?

Thanks!

SVG export affects ExtractTextPlugin export and vice versa

By having both ExtractTextPlugin and ExtractSVGPlugin on the same config makes SVG code appear into CSS and vice versa.

Configuration example:

module: { 
  loaders: [{
    test: /\.css$/,
    loader: ExtractTextPlugin.extract('style-loader', 'css-loader'),
  }, {
    test: /\.svg$/,
    loader: ExtractSVGPlugin.extract('svg-sprite-loader?extract=true'),
  }],
}, 
plugins: [
  new ExtractTextPlugin('[name].css', { allChunks: true }),
  new ExtractSVGPlugin('icons.svg'),
],

The problem could be solved by following ExtractTextPlugin guidelines on how to use 2 instances, however the library breaks if used like this:

var extractCSS = new ExtractTextPlugin('[name].css', { allChunks: true });
var extractSVG = new ExtractSVGPlugin('icons.svg');
// ...
module: { 
  loaders: [{
    test: /\.css$/,
    loader: extractCSS.extract('style-loader', 'css-loader'),
  }, {
    test: /\.svg$/,
    loader: extractSVG.extract('svg-sprite-loader?extract=true'),
  }],
}, 
plugins: [extractCSS, extractSVG],

I've made an example branch: https://github.com/albertogasparin/react-starterkit/tree/svg-extract
You can download it, npm install and then npm run build:assets to get the error.

1.0.0 release?

Any plans for a 1.0.0 release? ATM i have to change the package.json on every update manually, which annoys me more than it should.

Windows path problem

I've been trying to use 'entry' options to automatically load SVG sprite on windows machine.

My publicPath is './dist'.
Webpack plugin settings are
new SvgStore("svg/icons/*/.svg", "/", {
name: '[hash].sprite.svg',
chunk: 'head'
})

The code path.join(publicPath, filePath) from 109 line in index.js produces this code in the resulting chunk head.js:
svgXHR('\dist\8239235be0f2ba409fac873fb004346b.sprite.svg');

This causes the xhr request 404 error as the path is being read in javascript as 'dist8239235be0f2ba409fac873fb004346b.sprite.svg'.

ReferenceError: React is not defined

Hello,
I testing my react application with Mocha and when I run npm test I got the exception:
`app/DOM/pure/landing-assets/logo.svg:3
React.createElement(
^

ReferenceError: React is not defined`

How I can solve this problem?

CSS/<style> Support

Does svg-sprite-loader support <style> tags within the SVG's at all? Based on #27 I think the answer is no?

Usage with create-react-app

Hi,
I'm trying to make the loader work within create-react-app (https://github.com/facebookincubator/create-react-app)
but I'm having an issue and I can't figure out how to solve it:

client:75 ./src/css/app.scss
Module build failed: ReferenceError: document is not defined
    at new Sprite (!/blabla/node_modules/css-loader/index.js!/blabla/node_modules/postcss-loader/index.js!/blabla/node_modules/sass-loader/index.js!/blabla/src/css/app.scss:844:22)
    at Object.<anonymous> (!/blabla/node_modules/css-loader/index.js!/blabla/node_modules/postcss-loader/index.js!/blabla/node_modules/sass-loader/index.js!/blabla/src/css/app.scss:694:21)

This is how I added svg-sprite-loader to the webpack config: https://gist.github.com/Grsmto/7ee702886c5747f58689a228fc8517bc

Anyone you have any idea of how to debug this?

Thanks!

No icon rendered

I tried this loader yesterday, and I can't figure out how to load icons, I'm working on an angular 2 app so I created a component that does more or less the same job as the react-one in the examples (see code below) but it does not display any icon.

from the README.md:

By default sprite renders when DOMContentLoaded event fires and injects as first child in document.body

  • I don't see neither anything added to the body after page load (even before angular's bootstrap) nor a single reference to a sprite.js script in the list of sources in Chrome.
  • I don't have any output at compile or run time, it just does not render....
  • I removed my <base> tag

Here is my code :

import { Component, Input, OnInit, ElementRef} from '@angular/core';
var Glyphs = {};
var req = require.context("./icons", false, /\.svg$/);
req.keys().forEach(function(file: string) {
  var id = req(file);
  var name = /^\.\/(.*)\.svg$/.exec(file)[1];
  if (name) {
    Glyphs[name] = id;
  }
});

@Component({
  selector: 'lnk-icon',
  template: "",
  directives: [],
  providers: [],
  pipes: []
})
export class IconComponent implements OnInit {

  @Input("glyph")
  private glyph: string;

  constructor(private element: ElementRef) {
  }

  ngOnInit() {
    var svgns = "http://www.w3.org/2000/svg";
    var xlinkns = "http://www.w3.org/1999/xlink";
    var svg = document.createElementNS(svgns, "svg");
    var use = document.createElementNS(svgns, "use");
    use.setAttributeNS(xlinkns,"href",Glyphs[this.glyph]);
    svg.appendChild(use);
    this.element.nativeElement.appendChild(svg);
  }

}

and my webpack config:

//stuff
  module: {
     loaders:[{
      test: /\.svg$/,
      loader: "svg-sprite"
    }]
  },
//more stuff

Note that I first tried using Angular's template syntax but didn't work neither...

Update extract text plugin version [WebPack2]

Hi,

In extract-svg-plugin.js, the syntaxe of extract-text-webpack-plugin is deprecated :
this.extractPlugin = new ExtractPlugin(this.id, this.filename, this.options);

should be something like :
this.extractPlugin = new ExtractPlugin({ filename: this.filename, id: this.id});

There might be other changes as it's not enough to make this work again.

Thanks a lot.

Module build failed: TypeError: Must be an object

I'm trying to use svg-sprite-loader but I'm getting following error. Any idea what could be the reason for this?

I'm using webpack also with Babel and ES6.

ERROR in ./~/svg-sprite-loader!./src/assets/icons/image.svg
Module build failed: TypeError: Must be an object
    at exports.objectToAttrString (/PATH_TO_MY_PROJECT/node_modules/svg-sprite-loader/lib/utils.js:6:11)
    at SVGDocument.toString (/PATH_TO_MY_PROJECT/node_modules/svg-sprite-loader/lib/svg-document.js:29:18)
    at Object.module.exports (/PATH_TO_MY_PROJECT/node_modules/svg-sprite-loader/index.js:47:17)

IE Edge displays SVG on the homepage, but not others

I'm building an Angular2 app, and have my project set up to build with Webpack using this plugin.

Inside my app/assets/svg folder, I have my .svg files.

Inside my Webpack config:

entry: {
  'polyfills': './app/polyfills.ts',
  'vendor': './app/vendor.ts',
  'svg': './app/svg.js',
  'app': './app/main.ts'
},
...
module: {
  loaders: [
  {
    test: /\.svg$/,
    loader: 'svg-sprite'
  },
   ...
  ]
}

And inside app/svg.js:

var Glyphs = window.Glyphs = {};
var req = require.context(helpers.root("./assets/svg"), false, /\.svg$/);
req.keys().forEach(function(file) {
  var id = req(file);
  var name = /^\.\/(.*)\.svg$/.exec(file)[1];
  if (name) {
    Glyphs[name] = id;
  }
});

And then I'm inserting my SVGs into my Angular2 templates like this:

<svg>
  <use [attr.xlink:href]="'#my-svg'"></use>
</svg>

This displays correctly on all browsers except IE 11, and Edge versions 13 and 14 (tested using Browserstack). On IE, the SVG icons display correctly on the homepage, but when I navigate to other pages, they don't display at all. Looking in the DOM Inspector, I can see that the element is setting the xlink:href value to #my-svg correctly, and I can also see that the plugin has correctly inserted the svg code inside the top of the body tag, in the same way as it is inserted in other browsers. Yet, it only displays correctly on the homepage (the / page in my app) and not on pages that have longer routes like /home/foo.

By placing console.logs inside svg.js I can see that the file is also being executed every time each page is loading, so I thought that maybe the problem was that the path ./assets/ was working for the homepage / but not able to be found by pages like /home/foo. But when I try changing the path to something that would work for those pages, the Webpack build complains that it can't find that path, and I can see that the SVG data has been correctly inserted into the DOM with the correct ID anyway, so the <use> element should be able to reference it.

The svg is not outputted when using context

Maybe I'm doing something wrong, but:

Having my webpack config:

      {
        test: /img\/sprite\/.+\.svg$/,
        loader: 'svg-sprite'
      }

It will work, for a single file:

require('../img/sprite/icon-help.svg')

But I can't get it to work with context, trying this way:

var files = require.context('../img/sprite', true, /.svg$/)

The svg isn't added to the body of the page.

How can I use the svg in css

In our react project, we came across a situation when we had to use a third party library and we needed to apply our svg icons on their UI.

One way is to fork and fix it but I prefer if we could do it css whilst still using the sprited svgs.

Is this possible? If not what other option do I have apart from using the unsprited svg as is(which would be a separate request)

Module build failed: TypeError: Must be an object

Great plugin! It was working perfectly for me one minute, and then suddenly it started throwing this warning and not compiling. I tried rolling back my code to see if it was something I changed. Unfortunately it's having the same issue in all previous commits (even the ones that I know were working). Do you know what the issue is? Any help appreciated.

The Error

WARNING in ./~/svg-sprite-loader!./src/res/page-next.svg
Module build failed: TypeError: Must be an object
    at exports.objectToAttrString (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/lib/utils.js:6:11)
    at SVGDocument.toString (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/lib/svg-document.js:29:18)
    at Object.module.exports (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/index.js:47:17)
 @ ./src/res nonrecursive ./~/svg-sprite-loader!(page\-prev|page\-next)\.svg$

WARNING in ./~/svg-sprite-loader!./src/res/page-prev.svg
Module build failed: TypeError: Must be an object
    at exports.objectToAttrString (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/lib/utils.js:6:11)
    at SVGDocument.toString (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/lib/svg-document.js:29:18)
    at Object.module.exports (/Users/dave/Dropbox/Sites/ProductStream/node_modules/svg-sprite-loader/index.js:47:17)
 @ ./src/res nonrecursive ./~/svg-sprite-loader!(page\-prev|page\-next)\.svg$

Main script (relevant parts)

SVGs = require.context('svg-sprite!../res/', false, /(page\-prev|page\-next)\.svg$/);
SVGs.keys().forEach(SVGs);

webpack.config.js

module.exports = {
  entry: './src/index.js',
  output: {
    filename: './deploy/productstream.js'       
  },
  module: {
    loaders: [ // use ! to chain loaders
      { test: /\.html$/, loader: 'text-loader' },
      { test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' },
      { test: /\.css$/, loader: 'style-loader!css-loader' },
      // {test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'} // inline base64 URLs for <=8k images, direct URLs for the rest
      {
        test: /\.svg$/,
        loader: 'svg-sprite?' + JSON.stringify({
          name: '[name]_[hash]',
          prefixize: true,
          spriteModule: 'utils/my-custom-sprite'
        })
      }
    ]
  },
  resolve: {
    extensions: ['', '.js', '.json', '.coffee']
  }
};

Syles attributes overwritten due to multiple svg exported with style tags and same class names

Hi,

Not sure the title explains it well, so here a screenshot to help:

As you can see, the two expanded symbol -> defs -> style tag have the same class names. Therefore when the designer/frontend dev is tweaking the attributes in the style tag of the last svg required, it overwrites all the previous ones.

screen shot 2016-11-24 at 4 30 16 pm

There are different ways to tackle that issue that I know of. Having a lot of svgs and not being in contact with the designer, I am looking for a solution with this loader. Would that be interesting? Can the loader do it already (from my current understanding, it can't)? Am I the only one with that issue? I have some time to help with a PR if that can help.

Thanks for your answer, and thanks for that great loader!

Get viewBox for SVG tag

It seems (and I might be wrong) that SVG requires either specific width and height or viewBox and a single dimension to scale properly and preserve ratio.

Here's a a demo with code that's similar to what this loader generates:
http://codepen.io/elado/pen/GZdJZG?editors=1100

If no dimension or viewBox supplied, SVG defaults to 300x150 which is a browser default.
In the demo, the ones without the viewBox and only height get the 300px width.
Even though viewBox is defined on the <symbol>, the <svg><use ...> that will contain it won't grab it.

Is there a way to somehow import the viewBox to the SVG, or another workaround?

Sliced <g> in generated sprite

Hi, I have some svgs (exported from Sketch), which contain <g> element, but loader cuts it from generated sprite.

image

Examples:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="24px" height="25px" viewBox="0 0 24 25" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
    <!-- Generator: Sketch 3.4 (15588) - http://www.bohemiancoding.com/sketch -->
    <title>Contacts</title>
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Welcome" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
        <g id="Contact-(Requests)" sketch:type="MSArtboardGroup" transform="translate(-13.000000, -258.000000)" fill="#FAFAFA">
            <path d="M33.3522511,258 L18.2055175,258 C16.4814465,258 15.0787796,259.402667 15.0787796,261.126738 C15.0787796,261.308457 15.2259012,261.455579 15.4079439,261.455579 C15.5896633,261.455579 15.7367849,261.308457 15.7367849,261.126738 C15.7367849,259.765782 16.844562,258.658005 18.2055175,258.658005 L33.3522511,258.658005 C34.7132067,258.658005 35.8209837,259.765782 35.8209837,261.126738 L35.8209837,279.873262 C35.8209837,281.234218 34.7132067,282.341995 33.3522511,282.341995 L18.2055175,282.341995 C16.844562,282.341995 15.7367849,281.234218 15.7367849,279.873262 C15.7367849,279.691543 15.5896633,279.544098 15.4079439,279.544098 C15.2262245,279.544098 15.0787796,279.691219 15.0787796,279.873262 C15.0787796,281.597333 16.4814465,283 18.2055175,283 L33.3522511,283 C35.0763222,283 36.4789891,281.597333 36.4789891,279.873262 L36.4789891,261.126738 C36.4789891,259.402667 35.0763222,258 33.3522511,258 L33.3522511,258 Z M13.328841,264.131575 L17.4864001,264.131575 C17.6681196,264.131575 17.8152412,263.984454 17.8152412,263.802734 C17.8152412,263.621015 17.6681196,263.473893 17.4864001,263.473893 L13.328841,263.473893 C13.1471216,263.473893 13,263.621015 13,263.802734 C13,263.984454 13.1471216,264.131575 13.328841,264.131575 L13.328841,264.131575 Z M13.328841,268.596311 L17.4864001,268.596311 C17.6681196,268.596311 17.8152412,268.44919 17.8152412,268.26747 C17.8152412,268.085751 17.6681196,267.938306 17.4864001,267.938306 L13.328841,267.938306 C13.1471216,267.938306 13,268.085428 13,268.26747 C13,268.44919 13.1471216,268.596311 13.328841,268.596311 L13.328841,268.596311 Z M13.328841,273.061694 L17.4864001,273.061694 C17.6681196,273.061694 17.8152412,272.914572 17.8152412,272.732853 C17.8152412,272.551134 17.6681196,272.403689 17.4864001,272.403689 L13.328841,272.403689 C13.1471216,272.403689 13,272.55081 13,272.732853 C13,272.914572 13.1471216,273.061694 13.328841,273.061694 L13.328841,273.061694 Z M17.8155645,277.198236 C17.8155645,277.016516 17.6684429,276.869071 17.4867235,276.869071 L13.328841,276.869071 C13.1471216,276.869071 13,277.016193 13,277.198236 C13,277.379955 13.1471216,277.527077 13.328841,277.527077 L17.4864001,277.527077 C17.6684429,277.527077 17.8155645,277.379955 17.8155645,277.198236 L17.8155645,277.198236 Z M20.4443525,275.855064 C20.4679566,276.01706 20.6069946,276.13702 20.7702834,276.13702 L31.2864053,276.13702 C31.4496941,276.13702 31.5884088,276.016736 31.6123362,275.855064 C31.6285034,275.741894 31.9977625,273.057814 30.6015624,271.444973 C29.9345034,270.674444 28.9854883,270.283844 27.7813547,270.283844 C27.6943751,270.283844 27.6206526,270.326849 27.5605106,270.385698 L27.5521037,270.376968 C27.5462835,270.382788 26.9704075,270.926329 26.0291527,270.926329 C25.0878979,270.926329 24.5113752,270.382788 24.5068484,270.378261 L24.4984415,270.386991 C24.4379761,270.327496 24.3639303,270.283844 24.276304,270.283844 C23.0721704,270.283844 22.122832,270.674444 21.4560963,271.444973 C20.0589262,273.058137 20.4281853,275.742217 20.4443525,275.855064 L20.4443525,275.855064 Z M26.028506,271.584335 C26.4158723,271.584335 26.7476234,271.509965 27.0295795,271.411669 L26.028506,273.485598 L25.0267858,271.411345 C25.3090653,271.509965 25.6411397,271.584335 26.028506,271.584335 L26.028506,271.584335 Z M24.0713039,270.946377 L25.7323228,274.386112 C25.8422598,274.614393 26.2160456,274.613099 26.3246893,274.386112 L27.9850615,270.946377 C28.8910718,270.986795 29.602429,271.297852 30.102319,271.874374 C31.0610344,272.980211 31.0374303,274.786735 30.9879587,275.479338 L21.0684067,275.479338 C21.0176417,274.788029 20.9920975,272.985385 21.952753,271.875668 C22.4519963,271.298498 23.1643235,270.986795 24.0713039,270.946377 L24.0713039,270.946377 Z M29.1028622,266.662713 C29.1028622,264.96742 27.7237994,263.58868 26.0288294,263.58868 C24.3338593,263.58868 22.9541498,264.967743 22.9541498,266.662713 C22.9541498,268.358007 24.3338593,269.737393 26.0288294,269.737393 C27.7237994,269.737393 29.1028622,268.358007 29.1028622,266.662713 L29.1028622,266.662713 Z M23.6118318,266.662713 C23.6118318,265.330535 24.6960048,264.246686 26.028506,264.246686 C27.3606839,264.246686 28.4445335,265.330859 28.4445335,266.662713 C28.4445335,267.995538 27.3603606,269.079387 26.028506,269.079387 C24.6956814,269.079711 23.6118318,267.995538 23.6118318,266.662713 L23.6118318,266.662713 Z" id="Contacts" sketch:type="MSShapeGroup"></path>
        </g>
    </g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="25px" height="14px" viewBox="0 0 25 14" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
    <!-- Generator: Sketch 3.4 (15588) - http://www.bohemiancoding.com/sketch -->
    <title>Dashboard</title>
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Welcome" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
        <g id="Contact-(Requests)" sketch:type="MSArtboardGroup" transform="translate(-13.000000, -443.000000)" fill="#FAFAFA">
            <g id="Dashboard" sketch:type="MSLayerGroup" transform="translate(13.000000, 443.000000)">
                <path d="M12.5625,0.125 C12,0.125 11.46875,0.15625 10.90625,0.25 C10.75,0.28125 10.625,0.4375 10.625,0.59375 C10.65625,0.75 10.8125,0.875 10.96875,0.875 C11.5,0.8125 12,0.78125 12.53125,0.78125 C13.75,0.78125 14.90625,0.96875 16,1.3125 C16,1.34375 15.96875,1.34375 15.96875,1.375 L15.375,2.9375 C15.3125,3.09375 15.40625,3.28125 15.5625,3.34375 C15.59375,3.34375 15.625,3.375 15.6875,3.375 C15.8125,3.375 15.9375,3.3125 15.96875,3.1875 L16.5625,1.625 L16.5625,1.53125 C19.15625,2.5 21.34375,4.34375 22.71875,6.71875 L21.28125,7.53125 C21.125,7.625 21.0625,7.8125 21.15625,7.96875 C21.21875,8.0625 21.3125,8.125 21.4375,8.125 C21.5,8.125 21.53125,8.125 21.59375,8.09375 L23.03125,7.3125 C23.84375,8.90625 24.3125,10.71875 24.3125,12.625 C24.3125,12.8125 24.4375,12.9375 24.625,12.9375 C24.8125,12.9375 24.9375,12.8125 24.9375,12.625 C24.90625,5.6875 19.375,0.125 12.5625,0.125 L12.5625,0.125 Z" id="Shape" sketch:type="MSShapeGroup"></path>
                <path d="M6.90625,1.5 C2.75,3.625 0.1875,7.84375 0.1875,12.5 C0.1875,12.6875 0.3125,12.8125 0.5,12.8125 C0.6875,12.8125 0.8125,12.6875 0.8125,12.5 C0.8125,10.59375 1.28125,8.78125 2.09375,7.15625 L2.125,7.1875 L3.5625,8 C3.625,8.03125 3.65625,8.03125 3.71875,8.03125 C3.84375,8.03125 3.9375,7.96875 4,7.875 C4.09375,7.71875 4.03125,7.53125 3.875,7.4375 L2.4375,6.625 C2.40625,6.625 2.40625,6.625 2.375,6.59375 C3.46875,4.6875 5.125,3.0625 7.1875,2 C7.34375,1.90625 7.40625,1.71875 7.3125,1.59375 C7.25,1.46875 7.0625,1.40625 6.90625,1.5 L6.90625,1.5 Z" id="Shape" sketch:type="MSShapeGroup"></path>
                <path d="M9,0.5625 C8.90625,0.4375 8.78125,0.40625 8.625,0.4375 C8.5,0.5 8.40625,0.625 8.40625,0.75 C8.5,1.78125 9.46875,10.71875 9.75,11.53125 C10.25,12.96875 11.25,13.8125 12.40625,13.8125 L12.40625,13.8125 C12.71875,13.8125 13.03125,13.75 13.34375,13.65625 C14.875,13.09375 15.4375,11.5625 14.78125,9.71875 C14.53125,8.90625 9.5625,1.40625 9,0.5625 L9,0.5625 Z M13.1875,13.0625 C12.9375,13.15625 12.6875,13.1875 12.46875,13.1875 L12.46875,13.1875 C11.5625,13.1875 10.8125,12.5 10.375,11.3125 C10.1875,10.8125 9.625,5.84375 9.1875,1.9375 C11.34375,5.21875 14.0625,9.4375 14.25,9.9375 C14.65625,11.125 14.625,12.5625 13.1875,13.0625 L13.1875,13.0625 Z" id="Shape" sketch:type="MSShapeGroup"></path>
            </g>
        </g>
    </g>
</svg>

How to only inject symbols that are in use

when using style-loader, the loaded modules determine the css.

However, with sprite-loader, the common use is to have an Icon component that renders a component based on a list of glyphs. This means that when you load the Icon component, all the glyphs get injected in the file.

I would like to know the best technique so that only active glyphs are loaded, specifically for React โ‰ฅv0.14.

How about a singleton <Sprites/> component that you put somewhere in your app, which renders the current <symbol/> set, and then instead of <use hrefโ€ฆ you use <Sprite id={โ€ฆ}/> which, behind the scenes, updates the Sprites element based on refcounting in constructor and componentWillUnmount.

Furthermore, since you can put the sprites at the bottom of the page (proof), I believe that will also solve server side rendering since it will be stringified after all the icons were referenced.

why not including a server render spriteModule in the lib ?

just use like this:

var somePath = 'path/to/node_modules'

  module: {
    loaders: [
      {
        test: /\.svg/,
        // define path to custom sprite module
        loader: 'svg-sprite?spriteModule=' + path.resolve(somePath , 'svg-sprite-loader/server-side-rendering-sprite-module.js')
      }
    ]
  }

and this issues #19 (comment) doesn't return an id in Sprite.prototype.add
it should like this

function Sprite() {
  this.symbols = [];
}

const DEFAULT_URI_PREFIX = '#';

Sprite.prototype.add = function(image,id) {
  this.symbols.push(image);
  return `${DEFAULT_URI_PREFIX}${id}`;
};

Sprite.styles = ['position:absolute', 'width:0', 'height:0', 'visibility:hidden'];

Sprite.prototype.render = function() {
  return [
    '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="'+ Sprite.styles.join(';') +'">',
      '<defs>',
        this.symbols.join(''),
      '</defs>',
    '</svg>'
  ].join('');
};

module.exports = new Sprite();

ReferenceError: React is not defined

When using svg-sprite-loader , I always get ReferenceError: React is not defined.
I followed the instruction and listed my code below.
Did anyone confront the same problem ?

// webpack.config.js
{
    test: /\.svg$/,
    loader: 'svg-sprite?' + JSON.stringify({
      name: '[name]_[hash]',
      prefixize: true
    }),
    exclude: /node_modules/
}
// my_component.js
import iconSearch from './icon_search.min.svg';

Update Sprite styles

I am not sure why you chose visibility:hidden over display: none in the styles but this is not working with my configuration.

Instead of breaking this on everyone's configuration, I suggest to change Sprite.spriteTemplate to a function so we can easily update Sprite.styles in our implementation.

This is an example of what we could do:

var Sprite = require('svg-sprite-loader/lib/web/sprite')

// Replace visibility:hidden by display:none
Sprite.styles.pop()
Sprite.styles.push('display:none')

var globalSprite = new Sprite()

// ...

module.exports = globalSprite

If you think a PR is necessary just let me know.

Unexpected token windows

I've used this loader with great success on Linux/MacOS, but when I try to use it on Windows, I get this type of error message on all my SVG files:

ERROR in ./src/client/images/icons/ic_description_black_48px.svg
Module parse failed: C:\Users\<path>\src\client\images\icons\ic_description_black_48px.svg Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:0)
    at Parser.pp$4.raise (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
    at Parser.pp.unexpected (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
    at Parser.pp$3.parseExprAtom (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
    at Parser.pp$3.parseExprSubscripts (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:21)
    at Parser.pp$3.parseExpression (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:1573:21)
    at Parser.pp$1.parseStatement (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:727:47)
    at Parser.pp$1.parseTopLevel (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25)
    at Parser.parse (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17)
    at Object.parse (C:\Users\<path>\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39)
    at Parser.parse (C:\Users\<path>\node_modules\webpack\lib\Parser.js:902:15)
    at DependenciesBlock.<anonymous> (C:\Users\<path>\node_modules\webpack\lib\NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (C:\Users\<path>\node_modules\webpack-core\lib\NormalModuleMixin.js:310:10)
 @ ./src/client/components/policies/policy/PolicyHistory.jsx 57:33-95

What could be the issue here?

Using "svg-sprite-loader": "0.0.15",
npm -v 3.10.3
node -v 6.5.0

svg with clip-path doesn't display

I have an svg which includes a clip-path. When using it with this loader is doesn't display.

<svg>
  <defs>
    <clipPath id="mask">
      <circle cx="166.201" cy="166.201" r="166.201"/>
    </clipPath>
  </defs>
  <g clip-path="url(#mask)">
    ...
  </g>
</svg>

When debugging this I found that if I remove visibility: hidden from the injected svg with all the symbols it displays correctly. Is visibility: hidden needed?

<base> breaks icons

If a base element is present, the icons break, regardless if i'm using angular or not. Why not make a universal solution?

[Question] Getting Clip Path to work with custom sprite

Hi! I'm trying to resolve the issue of SVGs not appearing if they use clipping paths, using the method suggested in #60.

Here is the relevant part of my webpack config:

			{
				test: /\.svg$/,
				loader: 'svg-sprite?' + JSON.stringify({
					spriteModule: path.resolve(__dir, 'src', 'sprite')
				});
			}

And here is the sprite.js that the config references:

const Sprite = require('svg-sprite-loader/lib/web/sprite');

Sprite.styles.pop();
Sprite.styles.push('display:none');

module.exports = Sprite;

When I do this, I get an error that sprite.add is not a function.

Any thoughts on why this is not working, or when the display: none; fix referenced in #63 might be implemented?

prefixize fails for defs styles using fill: url(#name)

I am running [email protected].

prefixize.js seeks to adjust names of styles that use url(#myNameHere) to the appropriate generated ID. However, this fails for one of our use cases that has a linearGradient in a SVG def attribute.

Here is an example SVG image on codepen: http://codepen.io/troutr/pen/VaKMMR
Note the style named .simpleClass uses a fill to #simpleGradient.

<defs>
    <style>
    .simpleClass {
        fill: url(#simpleGradient);  /*This should get updated to a new name...??*/
    }

    .company-fill {
        fill: #18a7e0;
    }
    </style>
    <linearGradient id="simpleGradient" x1="5709.17" y1="20.01" x2="5724.1" y2="34.94" gradientUnits="userSpaceOnUse">
        <stop offset="0" stop-color="#003952" />
        ...etc etc
        <stop offset="0.99" stop-color="#003952" />
    </linearGradient>
</defs>

Note the gradient fill on the bottom half of the SVG image.
Result image with gradient

Running this SVG through prefixize: true produces the following results:

<defs>
    <style>
    .simpleClass {
        fill: url(#simpleGradient);  /* NOT UPGRADED! */
    }

    .company-fill {
        fill: #18a7e0;
    }
    </style>
    <linearGradient id="CompanyIcon_778e02c09f8a5ed0e12a9f654379ecbe_simpleGradient" x1="5709.17" y1="20.01" x2="5724.1" y2="34.94" gradientUnits="userSpaceOnUse">
        <stop offset="0" stop-color="#003952"></stop>
        ...etc etc
        <stop offset="0.99" stop-color="#003952"></stop>
    </linearGradient>
</defs>

This results in the following image:
Result image without gradient
I noticed that fill: url(#simpleGradient); is not updated to fill: url(#CompanyIcon_778e02c09f8a5ed0e12a9f654379ecbe_simpleGradient);.

Multiple entries, lazy loading and duplicates

I have multiple entries (chunks) that are lazy loaded in an AngularJS app.
When chunk is loaded, DOMContentLoaded is fired and SVGs are added again to DOM, creating duplicates. Can this somehow be avoided ?

Doesn't work on the server side

Thanks for the great work.
I'm trying to get this loader to work on server side as well. Since it's touches document directly, I guess getting it to work on the server is currently not possible. Can you please confirm?
If that is the case, do you have any plans of making it to work on the server as well?

extract-text-webpack-plugin@2 support in extract-svg-plugin

throw new Error("Breaking change: ExtractTextPlugin now only takes a single argument. Either an options " +
        ^

Error: Breaking change: ExtractTextPlugin now only takes a single argument. Either an options object *or* the name of the result file.
Example: if your old code looked like this:
    new ExtractTextPlugin('css/[name].css', { disable: false, allChunks: true })

You would change it to:
    new ExtractTextPlugin({ filename: 'css/[name].css', disable: false, allChunks: true })

The available options are:
    filename: string
    allChunks: boolean
    disable: boolean

Extra declared namespaces in SVG icons break SVG

I've traced an issue down to using extra declared namespaces, where the SVG's elements aren't included in the final sprite. Here's a sample SVG file exported from Sketch, a reasonably popular design tool:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
    <!-- Generator: Sketch 3.4.3 (16618) - http://www.bohemiancoding.com/sketch -->
    <title>test</title>
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Icons" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
        <g id="test" sketch:type="MSArtboardGroup" fill="#344043">
            <rect id="Rectangle-16" sketch:type="MSShapeGroup" x="4" y="4" width="8" height="8"></rect>
        </g>
    </g>
</svg>

(It's a simple square.)

It looks like svg-sprite-loader will grab the inner contents of the SVG and then insert it into a template that has the opening/closing SVG tags and run that through new DOMParser().parseFromString(...). At this point the SVG string looks like

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><symbol viewBox="0 0 16 16" id="dropbox"> <!-- Generator: Sketch 3.4.3 (16618) - http://www.bohemiancoding.com/sketch --> <title>test</title> <desc>Created with Sketch.</desc> <defs/> <g id="dropbox_Icons" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> <g id="dropbox_test" sketch:type="MSArtboardGroup" fill="#344043"> <rect id="dropbox_Rectangle-16" sketch:type="MSShapeGroup" x="4" y="4" width="8" height="8"/> </g> </g> </symbol></svg>

Note that there are sketch:* attributes like sketch:type present, but the xmlns:sketch declaration on the SVG is gone. DOMParser (on Chrome at least) will drop the outer <g> tag because of the invalid sketch attribute, and you end up with an empty symbol.

This isn't a blocking issue, since we can clean up our SVGs, but it would be nice if it just stripped the attributes or added the namespaces from the svg onto the template.

(Thanks for making this loader!)

[suggestion] Adding a `esModule` option for esModule interop

Thanks for writing this loader! It helps me a lot.

I'm migrating my JavaScript project to TypeScript. Then svg-sprite-loader has some issue with it's default export behavior.

microsoft/TypeScript#2719 has stated that import defaultimport from '...' will transpiled to var defaultImport = require('....').default

Now svg-loader is transpiled to module.export = XXX. If a esModule option is added, so user can control whether to transpile to module.export.default = xxx.

Now babel has transpiled code to esModule compatible code by default.
I think this is a desirable option for minority language user, and it embraces future node-esp.

If you don't mind, I can send a pull request.

Similar issue vuejs/vue-loader#349

make it server side renderable

trying to server side render my project with svg-sprite-loader returns me exceptions:

[ReferenceError: document is not defined]
ReferenceError: document is not defined
    at new o (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/~/svg-sprite-loader/lib/web/sprite.js:127:1)
    at Object.exports.modules.846 (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/~/svg-sprite-loader/lib/web/global-sprite.js:2:1)
    at e (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/webpack/bootstrap 5a43d80279dec3251221:25:1)
    at

down-caret.svg is one of the svg I am trying to load using the loader

TypeError: r.add is not a function
    at Object.exports.modules.926 (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/src/images/svg/down-caret.svg:4:1)
    at e (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/webpack/bootstrap 5a43d80279dec3251221:25:1)
    at [object Object].e.exports.NewSegmentButton.t.createClass.render (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/src/scripts/components/customer/EndUserList/NewSegmentButton.coffee:26:18)
    at [object Object].m._renderValidatedComponentWithoutOwnerOrContext (/Users/sliu/workplace/customer-web/deploy/assets/webpack:/~/react/lib/ReactCompositeComponent.js:587:1)

Doesn't support SSR (Serverside Rendering)

Injection into document.body is not possible during SSR, resulting in failure.

./sprite.webpack-module:128
  var baseElement = document.getElementsByTagName('base')[0];
                    ^
ReferenceError: document is not defined
    at new Sprite (./sprite.webpack-module:128:21)
    at Object.<anonymous> (/Users/dfarkov/Projects/core/canada-static/node_modules/svg-sprite-loader/lib/web/global-sprite.webpack-module:3:20)
    at Module._compile (module.js:460:26)
    at Object._module3.default._extensions.(anonymous function) [as .webpack-module] (/Users/dfarkov/Projects/core/canada-static/node_modules/webpack-isomorphic-tools/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:218:11)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/dfarkov/Projects/core/canada-static/app/assets/svg/ios-app-store.svg.webpack-module:3:14)
    at Module._compile (module.js:460:26)

Output a separate svg file

Do you know if there is a way to extract all svg icons and save them as an SVG bundle (in order to load them on page load)?
It would be really helpful on production, instead of having all those icons bundled together with the JS file.
I've tried with Webpack ExtractTextPlugin, but I got no output.

TypeError: must be an object

I have the following in the webpack.config.js:

module.exports = {
  entry: ["./utils", "./app.js"],
  output: {
    filename: "bundle.js"
  },
  module: {
  loaders: [
    {
      test: /\.svg$/,
      loader: 'svg-sprite'
    }
    ]
  },
  watch: true
}

In the same directory of my app.js file I have the legoMan.svg file. In the app.js file I have:

var id = require('svg-sprite!./legoMan.svg');
console.log('App loaded');

When I run webpack I get the following:

ERROR in ./~/svg-sprite-loader!./legoMan.svg
Module build failed: TypeError: Must be an object
    at exports.objectToAttrString (/webpack-test/node_modules/svg-sprite-loader/lib/utils.js:6:11)
    at SVGDocument.toString (/webpack-test/node_modules/svg-sprite-loader/lib/svg-document.js:29:18)
    at Object.module.exports (/webpack-test/node_modules/svg-sprite-loader/index.js:47:17)
 @ ./app.js 2:9-44

I have searched for this error, and found that for someone it was because they had another loader conflicting with svgs, however in my case the only loader that I have specified is svg-sprite. Does anyone have some insight as to why I might be getting this error?

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.