drdk / grunt-dr-svg-sprites

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

Fails to generate sprite with SVGs from Illustrator #26

Closed WillsB3 closed 10 years ago

WillsB3 commented 10 years ago

Am I doing something wrong here?

Things work (kind of..) if I export as SVG from sketch (apart from paths with boolean operations seem to cause problems, but that's perhaps a different issue), however whenever I try to export from illustrator the SVG is just blank. If i look at the source of the SVG there several occurrences of "NaN".

Here's the export settings I'm using:

screen shot 2014-08-08 at 09 35 47

Here's my gruntfile config (using grunt-load-config YAML syntax):

options:
  prefix: 'sprite'

sprite:
  options:
    spriteElementPath: '<%= src.assets %>/icons'
    spritePath: '<%= tmp.assets %>/icons/sprite.svg'
    cssPath: '<%= tmp.css %>/sprite.css'

The generated CSS looks like this:

.sprite-test {
    width: NaNpx;
    height: NaNpx;
    background-position: 0 0;
}

.sprite-test {
    background-size: NaNpx NaNpx;
    background-repeat: no-repeat;
    background-image: url("../assets/icons/sprite.png");
}

.svg .sprite-test {
    background-image: url("../assets/icons/sprite.svg");
}

If I open the very same SVG which Illustrator saved and then re-export it with sketch, it works.

Here's some test SVGs:

phloe commented 10 years ago

Looks like width and height attributes are omitted from the illustrator svg. Maybe because of the Responsive option?

Illustrator:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 53.5 53.5" enable-background="new 0 0 53.5 53.5" xml:space="preserve">

Sketch:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="54px" height="54px" viewBox="0 0 54 54" 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">
WillsB3 commented 10 years ago

That fixed it. Thanks!

Do you want me to fork and add this tidbit to the readme?

phloe commented 10 years ago

@WillsB3 A Troubleshooting section might be a good idea :) - though I would prefer it being added to the dr-svg-sprites readme. This repo is basically just a thin Grunt wrapper ;)

WillsB3 commented 10 years ago

Incase anyone else experiences this problem. The option that needs to be disabled is here:

screen-shot-2014-08-08-at-11 14 56

WillsB3 commented 10 years ago

@rasmusfl0e Done. See https://github.com/drdk/dr-svg-sprites/pull/29.

Thanks for this great utility :+1:

phloe commented 10 years ago

Good stuff - merged! :)