drdk / grunt-dr-svg-sprites

Grunt plugin to create SVG sprites with PNG fallbacks at needed sizes
113 stars 19 forks source link

Fatal error: Cannot call method 'replace' of undefined on sprite build #23

Closed Yokocapolo closed 10 years ago

Yokocapolo commented 10 years ago

After a few seconds I get the following error message when building the SVG sprite "Fatal error: Cannot call method 'replace' of undefined". Any ideas on how to fix this? Here is what is in the Grunt file.

"svg-sprites": {
      "images": {
        options: {
          spriteElementPath: "images",
          spritePath: "images/sprite-min.svg",
          cssPath: "stylesheets/sprite-min.css"
        }
      }
    },
Yokocapolo commented 10 years ago

Placing my svg minified files to another folder and setting the spriteElementPath to the new folder spriteElementPath: "images/sprites", removed the error but the sprite was empty. Changing the spritePath to spritePath: "images/sprite/test/sprite-min.svg", has partially worked, all the sprites are there but the viewbox and height attributes are set too small to contain all the svg images, increasing the height brings them into view, and increasing the viewBox 'unchops' part of one image. But this also means that the png fallback is missing an image and cutting part of another off.

phloe commented 10 years ago

What does the actual source of your svg's look like?

Yokocapolo commented 10 years ago

Just finished a quick test turns out the images where outside the artboards in the files with caused them to be out of view or chopped, so that was my fault. Just going to see if I can now create a sprite file from the origin folder now thats fixed.

Yokocapolo commented 10 years ago

Still can't make a sprite in the origin folder, are you planning on allowing same folder destinations? I don't like having to create a new folder to place files in.

phloe commented 10 years ago

@Yokocapolo The current behaviour is to take all files with a .svg extension from a folder and build a sprite from them. If you build your sprite to the same folder as spriteElementPath it would get included in the sprite on later builds (unless you have a task that specifically deletes it before building). I do have plans for exposing spriteElementPath as a glob - which would enable more finegrained control.