GithubHelp home page GithubHelp logo

gulp-svg-sprites's Introduction

gulp-svg-sprites Build Status

Table of contents

Install

Install it locally to your project.

$ npm install --save-dev gulp-svg-sprites

Windows note: Using Version < 4.0.0, make sure you also have all prerequisites for node-gyp.

Usage

With no configuration, gulp-svg-sprites will create the following files:

  1. svg/sprite.svg - Sprite Sheet containing all of your SVGs
  2. sprite.html - A preview page with instructions & snippets
  3. css/sprite.css - A CSS file with the code needed to use the sprite
var svgSprite = require("gulp-svg-sprites");

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite())
        .pipe(gulp.dest("assets"));
});

Then, if you had a facebook.svg file, you'd be able to use the following markup in your webpage:

<i class="icon facebook"></i>

PNG fallback

You can easily support old browsers by piping the new SVG sprite through to another gulp task. There will be a no-svg class generated automatically in the CSS, so you'll just need to use something like Modernizr to set the no-svg class on the <body> tag of your website.

var svgSprite = require("gulp-svg-sprites");
var filter    = require('gulp-filter');
var svg2png   = require('gulp-svg2png');

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite())
        .pipe(gulp.dest("assets")) // Write the sprite-sheet + CSS + Preview
        .pipe(filter("**/*.svg"))  // Filter out everything except the SVG file
        .pipe(svg2png())           // Create a PNG
        .pipe(gulp.dest("assets"));
});

Symbols mode

Pass mode: "symbols" to output SVG data as this CSS Tricks article outlines. You'll get an SVG file and a preview file showing how to use it.

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({mode: "symbols"}))
        .pipe(gulp.dest("assets"));
});

Defs mode

Pass mode: "defs" to output SVG data as this CSS Tricks article outlines. You'll get an SVG file and a preview file showing how to use it.

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({mode: "defs"}))
        .pipe(gulp.dest("assets"));
});

Custom selectors

By default, the filename will be used as the selector in the CSS, but this is how you'd override it (the %f will be replaced with the filename):

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            selector: "icon-%f"
        }))
        .pipe(gulp.dest("assets"));
});

Custom IDs

With the symbols or defs mode, it's probably the ID you'll want to override. No problem.

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            svgId: "svg-%f"
        }))
        .pipe(gulp.dest("assets"));
});

Custom filenames

You can also change the generated filenames with ease. For example, if you want to create a scss partial instead, you could just do:

// Custom CSS filename
gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            cssFile: "scss/_sprite.scss"
        }))
        .pipe(gulp.dest("assets"));
});

// Custom SVG filename
gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            svg: {
                sprite: "svg.svg"
            }
        }))
        .pipe(gulp.dest("assets"));
});

// Custom preview filename + custom SVG filename
gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            svg: {
                sprite: "svg.svg"
            },
            preview: {
                sprite: "index.html"
            }
        }))
        .pipe(gulp.dest("assets"));
});

Base size

Set the font-size of the .icon class. Just pass a plain number, no units.

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            baseSize: 16
        }))
        .pipe(gulp.dest("assets"));
});

No previews

If you don't want 'em. Works in all modes.

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            preview: false
        }))
        .pipe(gulp.dest("assets"));
});

Using the built-in SCSS template

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite({
            templates: { scss: true }
        }))
        .pipe(gulp.dest("assets"));
});

Advanced: custom templates

Templates use Lodash Templates - check out their docs for usage instructions. Or take a look at the default CSS or the default SCSS for tips.

You can get your hands on JUST the SVG Data and provide your own templates. For example, if you want to provide your own template for the CSS output, you could do this:

var config = {
    templates: {
        css: require("fs").readFileSync("./path/to/your/template.css", "utf-8")
    }
};

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite(config))
        .pipe(gulp.dest("assets"));
});

You can override all the templates used in the same way.

Advanced: data transforms

If you want to do some custom stuff with your templates, you might need to transform the SVG data before it gets to your template. There are two functions you can provide to do this and they'll override the internal ones. Override transformData and you'll have direct access to the data returned from svg-sprite-data. This will skip the few transformations that this library applies - so use with caution. (If you want to modify the data as well after our internal modifications, use afterTransform instead.)

// Synchronous
var config = {
    transformData: function (data, config) {
        return data; // modify the data and return it
    },
    templates: {
        css: require("fs").readFileSync("./path/to/your/template.css", "utf-8")
    }
};

// Asynchronous
var config = {
    asyncTransforms: true,
    transformData: function (data, config, done) {
        done(data); // modify the data and pass it
    },
    templates: {
        css: require("fs").readFileSync("./path/to/your/template.css", "utf-8")
    }
};

gulp.task('sprites', function () {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgSprite(config))
        .pipe(gulp.dest("assets"));
});

You can override all the templates used here in the same way. If you are doing any async work in these callbacks set asyncTransforms to true in the config.

Options

Name Type Default Description
mode String sprite

Define which mode to run in. Can be either "sprite", "defs" or "symbols"

common String icon

By default, the class icon will be used as the common class. You can also choose your own.

selector String %f

Easily add prefixes/suffixes to the generated CSS classnames. The %f will be replaced by the filename.

layout String vertical

Define the layout of the items in the sprite. Can be either "vertical", "horizontal" or "diagonal".

svgId String %f

In symbols or defs mode, you'll probably want to override the ID on each element. The filename will be used as a default, but can be overridden.

cssFile String css/sprite.css

Define the path & filename of the CSS file. Using this, you could easily create a SASS partial for example.

svgPath String ../%f

Define the path to the SVG file that be written to the CSS file. Note: this does NOT alter the actual write-path of the SVG file. See the svg option for that.

pngPath String ../%f

If you're creating a PNG fallback, define the path to it that be written to the CSS file

preview Object

Paths to preview files

preview.sprite String sprite.html
preview.defs String defs.html
preview.symbols String symbols.html
svg Object

Paths to SVG files

svg.sprite String svg/sprite.svg
svg.defs String svg/defs.svg
svg.symbols String svg/symbols.svg
padding Number 0

Add padding to sprite items

asyncTransforms Boolean false

Use async transforms

baseSize Number 10

Set the base font-size for the icon element

transformData Function transformData

Override the default data transforms

afterTransform Function afterTransform

Apply additional data transforms AFTER the defaults

License

Copyright (c) 2017 Shane Osbourne

Licensed under the MIT license.

gulp-svg-sprites's People

Contributors

4ver avatar alexanderflatscher avatar chpio avatar davidblurton avatar davidspiess avatar elivz avatar freelance-tech-writer avatar fyrebase avatar jakub-klapka avatar jodiwarren avatar moox avatar nikoskip avatar shakyshane avatar soenkekluth avatar thomaswelton 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

gulp-svg-sprites's Issues

Option to use px for positioning?

Is there a reason that ems are used for positioning, and is there an option to use px instead? I like ems for some things, but positioning sprites is not one of them.

Prevent PNG fallback being added to the CSS file

Not a big deal but I just noticed the following in the resultant CSS:

.no-svg .icon:before {
  background-image: url("../spritesheet.png");
}

I don't need any PNG fallback. I didn't see any option to disable this.


Out of curiousity, if I was using a PNG fallback, shouldn't it be possible to customize this bit of CSS? .no-svg looks like a class that Modernizr would add.

Paths relative to gulpfile

All the paths that can be passed as options are relative to the destination. Is it possible to pass a path relative to gulptfile?
Thank you.

Stripping out namespaces and NaN errors

Seems when I compile a folder of svgs generated by illustrator, gulp-svg-sprites strips out the namespaces which causes the compiled svg to error out with: Namespace prefix xlink for href on use is not defined.

Also getting a bunch of NaN's for the width, viewBox and several other params.

translate(-18.762-30.736) -> translate(NaN)

Given this input SVG - output from Inkscape, then run through SVGCleaner:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
    <g id="test_id">
        <path d="m443.45699 286.73599a168.69548 168.69548 0 1 1 -337.39097 0 168.69548 168.69548 0 1 1 337.39097 0" transform="translate(-18.762-30.736)" fill="#373737" color="#000"/>
    </g>
</svg>

and this gulpfile config:

gulp.task('icons', function () {
    gulp.src(src.icons)
        .pipe(newer(dest.icons))
        .pipe(cache('icons'))
        .pipe(svgs({ defs: true, generatePreview: false, generateCSS: false, svg: {defs: "sidebar-icons.svg"} }))
        .pipe(gulp.dest(dest.icons));
});

I get this output SVG:

<svg style="display:none" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <g id="test">
            <path d="M443.457 286.736a168.695 168.695 0 1 1-337.391 0 168.695 168.695 0 1 1 337.391 0" transform="translate(NaN)" fill="#373737" color="#000"/>
        </g>
    </defs>
</svg>

Notice how this:

transform="translate(-18.762-30.736)"

gets turned into this:

transform="translate(NaN)"

If I manually change the input SVG's transform to look like this:

transform="translate(-18.762, -30.736)"

I get this output:

transform="translate(-18.762 -30.736)"

I'm not 100% sure if the input transform="translate(-18.762-30.736)" is valid SVG or not - although it seems to work everywhere I tried it - see here for discussion on that.

Can't change CSS-selector output

When I try to to change the resulting selector output for the CSS-file, it just won't do anything.

Gulp-Task like this:

gulp.task('sprites', function () {
  return gulp.src('assets/sprites/*.svg')
    .pipe(sprites({
      selector: 'icon--%f', // BEM-style selectors
    }))
    .pipe(gulp.dest('assets/compiled/'));
});

I had a look at the source, threw in some console.logs, and realized that in the tmpl/sprite.css-Template 'selector' is not used, but 'name'.

When trying to debug the sprite-items, I got sth. like this (example sprite with one plus.svg file):

{ name: 'plus',
  height: 200,
  width: 200,
  last: true,
  selector:
   [ { expression: 'icon--plus',
       raw: 'icon--plus',
       first: true,
       last: true } ],
  positionX: 0,
  positionY: -315,
  position: '0 -315px',
  dimensions: { selector: [ [Object] ], width: 200, height: 200 },
  data: '<svg width="200" height="200" viewBox="0 0 200 200" id="plus" y="315"><path fill="#fff" d="M90 0v90H0v20h90v90h20v-90h90V90h-90V0z"/></svg>\n',
  raw: '<path fill="#fff" d="M90 0v90H0v20h90v90h20v-90h90V90h-90V0z"/>',
  viewBox: '0 0 200 200' }

Long story short, changing this part in tmpl/style.css from

{#svg}
.{name}:before {
    background-position: {relPositionX}em {relPositionY}em;
    width: {relWidth}em;
    height: {relHeight}em;
}
{/svg}

to

{#svg}
.{selector[0].expression}:before {
    background-position: {relPositionX}em {relPositionY}em;
    width: {relWidth}em;
    height: {relHeight}em;
}
{/svg}

works.

BUT: I don't think that this is intended and the way to do it... (thus no pull request ;-))

Possible to keep opacity?

Hi,

Is it possible to keep the paths with opacity 0 from being stripped out? I need to keep them in my SVG spritesheet for animation purposes, but they're being eliminated...

My config is

gulp.task('sprites', function () {
  gulp.src('src/svg/*.svg')
    .pipe(svgSprite({
        cssFile: 'src/sass/base/sprites.scss',
        svg: {
          symbols: 'images/symbols.svg'
        },
        preview: false,
        mode: 'symbols',
        selector: 'icon-%f'
      })
    )
    .pipe(replace(/ fill="#.+?"/g, ''))
    .pipe(gulp.dest('./client')); //client/images
});

Thanks!

--d

Generate Sass Map

Before i dive in - fantastic plugin - works wonders!


I have had a hack about with the project and got it to generate a Sass map instead of CSS classes. With a mixin, I was then able to have full control over all the attributes exported and where they were put.

As it is a custom hack, i have stripped out a lot of the code - but here is our working example:

https://github.com/liquidlight/gulp-svg-sprites/blob/master/lib/css-render.js

It generates code like:

$icons: (
    sprite: (width: 2395px, height: 61px, pngPath: '../img/sprite.png', svgPath: '../img/sprite.svg'),
    arrowLgBlack: (width: 24px, height: 23px, backgroundX: -0px, backgroundY: 0),
    arrowLgGreen: (width: 24px, height: 23px, backgroundX: -30px, backgroundY: 0),
    arrowLgRed: (width: 24px, height: 23px, backgroundX: -60px, backgroundY: 0)
);

This means in my Sass (with help from a mixin) I can do:

.class {
    @include sprite(arrowLgRed);
}

I am not a node developer, and ave probably employed several bad practices - would be great if something like this could be implemented.

Padding around images

I've been waiting for something like this for Gulp for what feels like ages, thank you for making it happen! I'm sure it's on your agenda anyway but the option to have padding around images in the sprites would be great...

Error: gulp[2876] (CarbonCore.framework) FSEventStreamFlushSync(): failed assertion '(SInt64)last_id > 0LL'

Error (in subject) is shown and SVG sprites task doesn't run when gulp-imagemin is used. After commenting out the gulp task for images processing, gulp-svg-sprites run (but without custom configuration #9).

Even when specific file extensions are defined, or changing order of tasks doesn't help.
Example of gulpfile partial below:

var svg = svgSprites.svg;
var png = svgSprites.png;

gulp.task('svg', function () {
    gulp.src('images/**/*.svg')
            .pipe(svg())
            .pipe(gulp.dest("./dist/images"))
            .pipe(png())
            .pipe(notify({ message: 'SVG sprites complete' }))
            .on("error", gutil.log);
});

// Images
gulp.task('images', function() {
  return gulp.src(['images/**/*'])
    .pipe(cache(imagemin({ pngquant: 5, optimizationLevel: 3, progressive: true, interlaced: true })))
    .pipe(livereload(server))
    .pipe(gulp.dest('dist/images'))
    .pipe(notify({ message: 'Images task complete' }))
    .on("error", gutil.log);
});

// Clean
gulp.task('clean', function() {
  return gulp.src(['dist/sass', 'dist/js', 'dist/images', 'dist/svg'], {read: false})
    .pipe(clean())
    .on("error", gutil.log);
});

// Default task
gulp.task('default', ['clean'], function() {
    gulp.start('styles', 'scripts', 'images', 'svg');
    // gulp.start('styles', 'scripts', 'svg');
});

// Watch
gulp.task('watch', function() {

  // Listen on port 35729
  server.listen(35729, function (err) {
    if (err) {
      return console.log(err)
    };

    // Watch .scss files
    gulp.watch('sass/**/*.scss', ['styles']);

    // Watch .js files
    gulp.watch('js/**/*.js', ['scripts']);

    // Watch image files
    gulp.watch('images/**/*', ['images']);

    //Watch .svg files and make sprites with PNG fallback
    gulp.watch('images/**/*.svg', ['svg']);
  });

});

Is it possible to output a Sass placeholder(%) rather than a class(.)

I would like the generated (s)css to output Sass placeholders instead of classes, as then I can keep a tidier codebase, including when needed and avoiding duplicated code.

At the moment, if I add into config, for example:
className: "%sprite--%f"
I get output
.%sprite--a

When the desired output would be
%sprite--a

Could this be possible?

Dependency on Python

We noticed that the newer versions have a dependency on node-gyp and Python.
Out of curiosity, what is node-gyp used for?

Consider providing a JS loading script

What would you think about providing a JS loading script when the sprite is generated?

I'm using the <symbol> pattern, and instead of pasting the contents of the SVG file into the head of my doc I'd like to keep the spritesheet external and then inline the contents via AJAX (so the sprite is both cached separately from the page and loaded asynchronously).

(Grunticon, for example, generates a simple loading script and provides it along with the other generated resources. Or here's an example somebody wrote for grunt-svgstore: https://gist.github.com/w0rm/621a56a353f7b2a6b0db.)

Add cleanconfig option to README

It takes me plenty of time to find out that there is SVGO inside this plugin and I can configure it. I guess it would be useful to make it clear in README.

Errors in CSS Output

The CSS is outputting incorrect/invalid mark up just after the star element: "background: -100px 0

See below example:

.logo-t {
    width: 80px;
    height: 80px;
}

.printer {
    width: 80px;
    height: 80px;
}

.star {
    width: 80px;
    height: 80px;
}
position: -100px 0;
}

.star {
    width: 80px;
    height: 80px;
    background-position: -200px 0;
}

.no-svg .logo-t,
.no-svg .printer,
.no-svg .star {
    display: inline-block;
    background-image: url("../icons.sprite.png");
    background-size: 300px 80px;
}

.logo-t,
.printer,
.star {
    display: inline-block;
    background-image: url("../icons.sprite.svg");
    background-repeat: no-repeat;
}

This occurs using the below SVG Config:

var svgConfig = {
    className: ".%f",
    cssFile:   "css/sprites.css",
    preview: {
        sprite: "preview-svg-sprite.html",
        defs: "preview-svg.html"
    },
    svg: {
        sprite: "icons.sprite.svg",
        defs: "icons.defs.svg"
    },
    padding: 20,
};

Install fails on v0.11.14

It starts with warning

npm WARN engine [email protected]: wanted: {"node":"0.6.x"} (current: {"node":"0.11.14","npm":"2.1.3"})

and then lot of errors appear

In file included from ../src/libxmljs.cc:8:
../src/xml_document.h:11:34: error: expected class name
class XmlDocument : public node::ObjectWrap {

Not installing

When I write, npm install gulp-svg-sprites, I'm being told in the cmd,

npm ERR! 404 'gulp-svg-sprites' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

Escape Less variables in templates

I have this this kind of CSS template

.{common} {
    vertical-align:middle;
    display: inline-block;
    background-image: url('/frontend/core/images/pictos.svg?v=@{cacheVersion}');
    background-repeat: no-repeat;
    background-size: {relWidth} * 10px;
}

How can I escape Less/Sass variables ?

Gradient is broken because svg-sprite-data replaces ids

I can't say is anything wrong with svg-sprite-data https://github.com/shakyShane/svg-sprite-data , so I post it here

Before

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="21px" height="17px" viewBox="0 0 21 17" 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 Beta 3.0.4 (7942) - http://www.bohemiancoding.com/sketch -->
    <title>Team Icon</title>
    <desc>Created with Sketch Beta.</desc>
    <defs>
        <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
            <stop stop-color="#4C4C4C" offset="0%"></stop>
            <stop stop-color="#7F7F7F" offset="100%"></stop>
        </linearGradient>
    </defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
        <g id="Team-Icon" sketch:type="MSLayerGroup" fill="url(#linearGradient-1)">
            <path d="M12.8967807,7.87764369 C13.8978694,7.08861613 14.5479327,5.78518845 14.5479327,4.35193263 C14.5479327,1.95771469 12.7355755,0 10.4998908,0 C8.26420609,0 6.4518489,1.93268477 6.4518489,4.3269027 C6.4518489,5.76015852 7.10191218,7.09282677 8.10300088,7.88185433 C5.81270738,8.87650159 4.2,11.3858104 4.2,14.1929052 C4.2,17.9356983 16.8,17.9356983 16.8,14.1929052 C16.7995631,11.3860443 15.1870742,8.87252487 12.8967807,7.87764369 Z M18.0539732,7.30351383 C18.8097097,6.7404596 19.3001535,5.82308324 19.3001535,4.79986449 C19.3001535,3.09071441 17.9322032,1.7 16.2446906,1.7 C15.8657011,1.7 15.5030822,1.77041017 15.1682707,1.89782986 C15.4077741,2.47065066 15.5405326,3.10002672 15.5405326,3.76051954 C15.5405326,4.97884259 15.0805873,6.14719714 14.28,7.02550722 C16.4752239,8.26858741 17.8525929,10.6348234 17.8525929,13.2724791 C17.8525929,13.3765045 17.8442955,13.4864352 17.8254582,13.6 C19.5735193,13.377413 21,12.7725669 21,11.7852347 C21,9.66089172 19.7827484,8.01374802 18.0539732,7.30351383 Z M3.26499724,13.2480135 C3.26499724,10.6639837 4.55795098,8.34173396 6.62728778,7.0847364 C6.65891901,7.05459203 6.68967765,7.02331441 6.72,6.9920368 C5.95386983,6.11649017 5.51386853,4.9558186 5.51386853,3.74301767 C5.51386853,3.11746534 5.63188573,2.52024417 5.84414218,1.97243258 C5.47220256,1.79791254 5.06012401,1.7 4.62579451,1.7 C2.98424282,1.7 1.65354975,3.08006819 1.65354975,4.78560491 C1.65354975,5.80688709 2.13085408,6.73116334 2.86578932,7.2930272 C1.18431683,8.00175987 0,9.6440614 0,11.7639132 C0,12.7888218 1.501938,13.4007752 3.29531959,13.6 C3.27415939,13.4776093 3.26499724,13.3597516 3.26499724,13.2480135 Z" sketch:type="MSShapeGroup"></path>
        </g>
    </g>
</svg>

After

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="21" height="17" viewBox="0 0 21 17"><svg width="21" height="17" viewBox="0 0 21 17" id="team" y="0"><title>Team Icon</title><desc>Created with Sketch Beta.</desc><defs><linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="aaa-hey-yo"><stop stop-color="#4C4C4C" offset="0%"/><stop stop-color="#7F7F7F" offset="100%"/></linearGradient></defs><path d="M12.897 7.878c1-.79 1.65-2.093 1.65-3.526C14.548 1.958 12.738 0 10.5 0 8.264 0 6.452 1.933 6.452 4.327c0 1.433.65 2.766 1.65 3.555-2.29.995-3.902 3.504-3.902 6.31 0 3.744 12.6 3.744 12.6 0 0-2.806-1.613-5.32-3.903-6.314zm5.157-.574C18.81 6.74 19.3 5.824 19.3 4.8c0-1.71-1.368-3.1-3.055-3.1-.38 0-.742.07-1.077.198.24.573.373 1.202.373 1.863 0 1.22-.46 2.387-1.26 3.266 2.195 1.243 3.573 3.61 3.573 6.246 0 .105-.01.214-.028.328 1.75-.223 3.175-.827 3.175-1.815 0-2.124-1.217-3.77-2.946-4.48zm-14.79 5.944c0-2.584 1.294-4.906 3.363-6.163.032-.03.063-.062.093-.093-.766-.876-1.206-2.036-1.206-3.25 0-.625.118-1.222.33-1.77-.372-.174-.784-.272-1.218-.272-1.642 0-2.972 1.38-2.972 3.086 0 1.02.477 1.945 1.212 2.507C1.184 8.003 0 9.643 0 11.763c0 1.026 1.502 1.638 3.295 1.837-.02-.122-.03-.24-.03-.352z" fill="url(#aaa)"/></svg>
</svg>

ID of <linearGradient> is aaa-hey-yo and <path>'s attribute is fill="url(#aaa)", but they must be the same.

Standard background size for svg

Chrome has issues with the svg sprite, without the background size property. Is it possible to include this also als a standard, just like the no-svg sprites.

Duplicate ID's in SVG output

Got a situation where I get invalid output because of a <g> element ending up with multiple id attributes.

Given this input SVG (called data-policy-3.svg):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   version="1.1"
   id="Layer_1"
   x="0px"
   y="0px"
   width="512"
   height="512"
   viewBox="0 0 512 511.99999"
   enable-background="new 0 0 100 86.915"
   xml:space="preserve"
   inkscape:version="0.48.4 r9939"
   sodipodi:docname="data-policy-3.svg"><metadata
     id="metadata3128"><rdf:RDF><cc:Work
         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
     id="defs3126" /><sodipodi:namedview
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1"
     objecttolerance="10"
     gridtolerance="10"
     guidetolerance="10"
     inkscape:pageopacity="0"
     inkscape:pageshadow="2"
     inkscape:window-width="1920"
     inkscape:window-height="1056"
     id="namedview3124"
     showgrid="false"
     inkscape:zoom="0.96000229"
     inkscape:cx="282.62837"
     inkscape:cy="218.78551"
     inkscape:window-x="1920"
     inkscape:window-y="0"
     inkscape:window-maximized="1"
     inkscape:current-layer="Layer_1" /><g
     id="g3231"
     transform="matrix(5.12,0,0,5.12,0,-2142.9376)"
     style="fill:#373737;fill-opacity:1"><path
       style="fill:#373737;fill-opacity:1"
       inkscape:connector-curvature="0"
       id="path3120"
       d="m 89.332,453.297 -11,18.666 6.284,0.057 c -0.784,7.969 -4.277,15.374 -10.007,21.103 -6.563,6.564 -15.297,10.18 -24.581,10.18 -9.289,0 -18.017,-3.615 -24.586,-10.18 -1.691,-1.695 -4.446,-1.695 -6.142,0 -1.701,1.696 -1.701,4.451 0,6.146 8.209,8.209 19.117,12.731 30.728,12.731 11.605,0 22.519,-4.522 30.728,-12.731 7.354,-7.354 11.754,-16.906 12.584,-27.173 l 6.66,0.06 -10.668,-18.859 z" /><path
       style="fill:#373737;fill-opacity:1"
       inkscape:connector-curvature="0"
       id="path3122"
       d="m 15.379,465.679 c 0.662,-8.207 4.17,-15.825 10.062,-21.719 6.569,-6.567 15.297,-10.183 24.586,-10.183 9.284,0 18.018,3.616 24.581,10.183 1.696,1.696 4.446,1.696 6.146,0 1.696,-1.698 1.696,-4.448 0,-6.146 -8.208,-8.207 -19.121,-12.729 -30.726,-12.729 -11.611,0 -22.519,4.522 -30.728,12.729 -7.557,7.56 -11.978,17.383 -12.639,27.944 L 0,465.816 l 11,18.664 10.664,-18.857 -6.285,0.056 z" /></g><style
     type="text/css"
     id="style3">
    .st0{fill:none;}
    .st1{fill:#373737;}
</style><g
     id="g3360"
     transform="matrix(0.49727048,0,0,0.49727048,128.69876,128.69875)"><g
       transform="translate(0,412)"
       id="Captions" /><path
       sodipodi:nodetypes="sscccssscccsscscscssccscssccssascccscccccccscccccccccccsccccccc"
       style="fill:#373737;fill-opacity:1"
       inkscape:connector-curvature="0"
       id="path8"
       d="M 256.28761,0 C 135.61293,0 41.090483,51.840256 41.090483,118.02061 c 0,1.68529 0.121099,3.36048 0.252289,5.04072 l -0.252289,0 c 0,0 -0.06055,37.19239 -0.267425,84.3199 -0.121099,63.85929 -0.312838,153.8511 -0.312838,186.65366 0,66.1198 94.19951,117.96511 214.55127,117.96511 119.95818,0 213.90541,-51.84531 213.90541,-117.96511 0,-18.00835 0.25733,-59.65663 0.58027,-97.22745 0.772,-79.80897 1.86693,-177.17219 1.94261,-178.5951 0,-0.0605 0,-0.12614 0,-0.19678 C 471.48474,51.840256 376.95725,0 256.28761,0 z M 87.99326,388.91638 c 0,-9.49109 0,2.81565 0.0656,-13.39137 33.71585,36.21351 85.78084,48.74397 168.2338,48.74397 80.1319,0 130.5772,-15.10657 165.3123,-49.64488 -0.0555,14.9809 -0.1211,1.50859 -0.1211,10.35382 0,47.78346 -66.60186,80.31813 -166.41732,80.31813 -100.15353,0.005 -167.073276,-28.59621 -167.073276,-76.37967 z M 256.41376,43.463703 c 51.82648,-0.443756 163.63728,18.731038 169.8998,74.193707 -4.59361,33.25006 -43.77678,46.91029 -66.33534,54.37899 -29.765,9.81908 -65.60008,15.62676 -103.69061,15.62676 -38.09558,0 -73.9357,-5.80264 -103.69566,-15.62676 C 122.68087,164.00988 97.197251,147.7367 96.413995,117.65741 94.820408,56.459217 222.86271,43.750977 256.41376,43.463703 z M 88.053809,319.62809 c 0.07064,-19.31017 0.126144,-8.53202 0.126144,-29.71417 0.201832,-0.57522 0.09864,-2.20224 0.524761,-1.80134 6.618192,6.22643 7.803453,6.84797 16.298746,12.55478 37.72907,25.34491 99.63246,33.06168 151.27911,33.5085 49.44594,0.42778 107.63842,-4.23848 145.36636,-29.57004 7.85063,-5.27112 14.84971,-10.97959 20.78859,-16.97902 -0.26238,20.91473 -0.44908,9.88934 -0.65091,28.87657 0,1.93254 0,3.73892 0,5.6109 -25.62243,38.09054 -81.43644,54.55166 -165.50404,54.55166 -85.61666,0 -142.5912,-15.59186 -166.866402,-54.71173 -0.514669,-0.77705 -0.968788,-1.54906 -1.362359,-2.32611 z m 1.680243,-126.0929 c 3.421033,3.1637 7.170042,6.19622 11.110788,9.10257 2.06373,1.54401 4.19809,3.03251 6.39804,4.51597 2.05867,1.35731 4.1224,2.70959 6.32236,4.07194 10.7828,6.57969 9.36187,6.18823 22.72812,11.28445 34.86628,13.30066 73.37132,13.53614 119.98921,13.53614 46.61284,0 89.28998,-5.09016 124.15121,-18.39082 13.30066,-5.09622 7.13274,-1.81931 17.97106,-8.399 2.13436,-1.36236 4.26368,-2.64903 6.33748,-4.07194 2.25546,-1.48346 4.38982,-2.97196 6.45355,-4.51597 3.93065,-2.91141 7.67461,-5.93887 11.09565,-9.04201 0.13119,0.19678 0.26743,0.45411 0.38348,0.6408 -0.11605,10.01081 -0.25229,20.723 -0.38348,31.95993 -0.0656,6.51914 -0.12614,-3.4188 -0.1867,3.36271 0,0.96879 0,1.94262 0,2.90636 -1.36235,2.12932 -2.83572,4.19809 -4.521,6.2618 -6.14576,7.68472 -14.21394,14.92035 -23.96237,21.50509 -35.44151,24.08347 -74.27178,28.21776 -137.34898,28.21776 -63.08224,0 -102.50253,-2.16001 -137.94907,-26.24853 -9.75852,-6.58474 -17.81662,-13.81533 -23.952284,-21.50508 -1.942622,-2.45225 -3.678368,-4.90449 -5.232465,-7.42233 -0.317884,-0.51467 -0.640814,-1.03439 -0.898148,-1.5541 0.06055,-5.74209 0.06055,5.16464 0.06055,-0.38571 0.07064,-11.88279 0.07064,-23.18027 0.13119,-33.64016 0.403662,-0.71146 0.782095,-1.48851 1.301805,-2.18987 z" /></g></svg>

with this gulpfile config:

gulp.task('icons', function () {
    gulp.src(src.icons)
        .pipe(newer(dest.icons))
        .pipe(cache('icons'))
        .pipe(svgs({ defs: true, generatePreview: false, generateCSS: false, svg: {defs: "sidebar-icons.svg"} }))
        .pipe(gulp.dest(dest.icons));
});

I get this output (I've added linebreaks & whitespace back in for clarity):

<svg style="display:none" xmlns="http://www.w3.org/2000/svg">]
    <defs>
        <g id="data-policy-3" id="g3231" fill="#373737">
            <path id="path3120" d="M457.38 177.943l-56.32 95.57 32.174.292c-4.014 40.801-21.898 78.715-51.236 108.047-33.603 33.608-78.321 52.122-125.855 52.122-47.56 0-92.247-18.509-125.88-52.122-8.658-8.678-22.764-8.678-31.447 0-8.709 8.684-8.709 22.789 0 31.468 42.03 42.03 97.879 65.183 157.327 65.183 59.418 0 115.297-23.153 157.327-65.183 37.652-37.652 60.18-86.559 64.43-139.126l34.099.307-54.62-96.558z"/>
            <path id="path3122" d="M78.74 241.339c3.389-42.02 21.35-81.024 51.517-111.201 33.633-33.623 78.321-52.137 125.88-52.137 47.534 0 92.252 18.514 125.855 52.137 8.684 8.684 22.764 8.684 31.468 0 8.684-8.694 8.684-22.774 0-31.468-42.025-42.02-97.9-65.172-157.317-65.172-59.448 0-115.297 23.153-157.327 65.172-38.692 38.707-61.327 89.001-64.712 143.073l-34.104.297 56.32 95.56 54.6-96.548-32.179.287z"/>
        </g>
        <style type="text/css" id="style3">.st0{fill:none;} .st1{fill:#373737;}</style>
        <g id="g3360">
            <path id="path8" d="M256.143 128.699c-60.008 0-107.011 25.779-107.011 58.688 0 .838.06 1.671.125 2.507h-.125s-.03 18.495-.133 41.93c-.06 31.755-.156 76.506-.156 92.817 0 32.879 46.843 58.661 106.69 58.661 59.652 0 106.369-25.781 106.369-58.661 0-8.955.128-29.665.289-48.348.384-39.687.928-88.102.966-88.81v-.098c-.003-32.907-47.008-58.686-107.014-58.686zm-83.688 193.397c0-4.72 0 1.4.033-6.659 16.766 18.008 42.656 24.239 83.658 24.239 39.847 0 64.932-7.512 82.205-24.687-.028 7.45-.06.75-.06 5.149 0 23.761-33.119 39.94-82.754 39.94-49.803.002-83.081-14.22-83.081-37.981zm83.751-171.783c25.772-.221 81.372 9.314 84.486 36.894-2.284 16.534-21.769 23.327-32.987 27.041-14.801 4.883-32.621 7.771-51.562 7.771-18.944 0-36.766-2.885-51.565-7.771-14.874-3.991-27.546-12.084-27.936-27.041-.792-30.432 62.879-36.751 79.563-36.894zm-83.72 137.328c.035-9.602.063-4.243.063-14.776.1-.286.049-1.095.261-.896 3.291 3.096 3.88 3.405 8.105 6.243 18.762 12.603 49.544 16.441 75.227 16.663 24.588.213 53.525-2.108 72.286-14.704 3.904-2.621 7.384-5.46 10.338-8.443-.13 10.4-.223 4.918-.324 14.359v2.79c-12.741 18.941-40.496 27.127-82.3 27.127-42.575 0-70.906-7.753-82.978-27.207-.256-.386-.482-.77-.677-1.157zm.836-62.702c1.701 1.573 3.565 3.081 5.525 4.526 1.026.768 2.088 1.508 3.182 2.246 1.024.675 2.05 1.347 3.144 2.025 5.362 3.272 4.655 3.077 11.302 5.611 17.338 6.614 36.485 6.731 59.667 6.731 23.179 0 44.401-2.531 61.737-9.145 6.614-2.534 3.547-.905 8.936-4.177 1.061-.677 2.12-1.317 3.151-2.025 1.122-.738 2.183-1.478 3.209-2.246 1.955-1.448 3.816-2.953 5.518-4.496l.191.319c-.058 4.978-.125 10.305-.191 15.893l-.093 1.672v1.445c-.677 1.059-1.41 2.088-2.248 3.114-3.056 3.821-7.068 7.419-11.916 10.694-17.624 11.976-36.933 14.032-68.3 14.032-31.369 0-50.971-1.074-68.598-13.053-4.853-3.274-8.86-6.87-11.911-10.694-.966-1.219-1.829-2.439-2.602-3.691-.158-.256-.319-.514-.447-.773.03-2.855.03 2.568.03-.192.035-5.909.035-11.527.065-16.728.201-.354.389-.74.647-1.089z" fill="#373737"/>
        </g>
    </defs>
</svg>

The problem in the output is this: <g id="data-policy-3" id="g3231" fill="#373737"> which looks like this in the input:

<g
     id="g3231"
     transform="matrix(5.12,0,0,5.12,0,-2142.9376)"
     style="fill:#373737;fill-opacity:1">

This means that the output isn't valid XML, so not valid SVG either - I can't find anything which will open it, for example.

CSS values being set as NaNpx

For some reason the CSS output is returning NaNpx, like below

.action-voted {
    width: NaNpx;
    height: NaNpx;
    background-position: -NaNpx 0;
}

add templates into config

Hey thanks for this cool plugin
What do you think about adding the differente templates to the config object
right now I am using this hack to output the file i need

  require('gulp-svg-sprites/lib/svg-utils').templates.defs = '<defs>{:shapes:}</defs>';

  gulp
    .src('public/images/svg/*.svg')
    .pipe(svgSprites.svg({
      defs: true,
      generateCSS: false,
      generatePreview: false
    }))
    .pipe(gulp.dest('public/images'));

Wrong fill color

Sometimes when I add new icon to my project there is a problem with SVG output. For some reason I am getting the wrong fill color when icon has it fill color defined in class, and not like inline style. Also, I am missing <g> element in output.

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.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"
     width="42px" height="42px" viewBox="0 0 42 42" style="enable-background:new 0 0 42 42;" xml:space="preserve">
<style type="text/css">
    .st0{fill-rule:evenodd;clip-rule:evenodd;fill:#3C7057;}
</style>
<path class="st0" d="M34,25c-1.841,0-3.55,0.555-4.976,1.503C29.63,25.294,30,23.946,30,22.5c0-0.828-0.672-1.5-1.5-1.5
    c-0.828,0-1.5,0.672-1.5,1.5c0,3.314-2.686,6-6,6c-3.314,0-6-2.686-6-6c0-0.828-0.672-1.5-1.5-1.5c-0.828,0-1.5,0.672-1.5,1.5
    c0,4.458,3.245,8.15,7.5,8.865V34h3v-2.635c1.272-0.214,2.435-0.719,3.467-1.406C25.353,31.175,25,32.545,25,34
    c0,2.297,0.868,4.387,2.285,5.977C25.307,40.632,23.198,41,21,41C9.954,41,1,32.046,1,21S9.954,1,21,1s20,8.954,20,20
    c0,2.198-0.368,4.307-1.023,6.285C38.387,25.868,36.297,25,34,25z M25.5,21h-2.25c-0.414,0-0.75-0.336-0.75-0.75
    c0-0.414,0.336-0.75,0.75-0.75h2.25V18h-2.25c-0.414,0-0.75-0.336-0.75-0.75s0.336-0.75,0.75-0.75h2.25V15h-2.25
    c-0.414,0-0.75-0.336-0.75-0.75c0-0.414,0.336-0.75,0.75-0.75h1.974c-0.62-1.744-2.268-3-4.225-3c-1.956,0-3.604,1.256-4.224,3
    h1.975c0.414,0,0.75,0.336,0.75,0.75c0,0.414-0.336,0.75-0.75,0.75H16.5v1.5h2.25c0.414,0,0.75,0.336,0.75,0.75S19.164,18,18.75,18
    H16.5v1.5h2.25c0.414,0,0.75,0.336,0.75,0.75c0,0.414-0.336,0.75-0.75,0.75H16.5v1.5c0,2.485,2.015,4.5,4.5,4.5
    c2.485,0,4.5-2.015,4.5-4.5V21z M34,27c3.866,0,7,3.134,7,7s-3.134,7-7,7s-7-3.134-7-7S30.134,27,34,27z M34,39c2.761,0,5-2.239,5-5
    s-2.238-5-5-5c-2.761,0-5,2.239-5,5S31.239,39,34,39z M33,30.969h2v2h2v2h-2v2h-2v-2h-2v-2h2V30.969z"/>
</svg>

For me, only solution is to implement class style to inline stile and add <g> element in every icon that has wrong output. After applying this changes I am getting the right color:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.0.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"
     width="42px" height="42px" viewBox="0 0 42 42" style="enable-background:new 0 0 42 42;" xml:space="preserve">

<g>
<path style="fill-rule:evenodd;clip-rule:evenodd;fill:#3C7057;" d="M34,25c-1.841,0-3.55,0.555-4.976,1.503C29.63,25.294,30,23.946,30,22.5c0-0.828-0.672-1.5-1.5-1.5
    c-0.828,0-1.5,0.672-1.5,1.5c0,3.314-2.686,6-6,6c-3.314,0-6-2.686-6-6c0-0.828-0.672-1.5-1.5-1.5c-0.828,0-1.5,0.672-1.5,1.5
    c0,4.458,3.245,8.15,7.5,8.865V34h3v-2.635c1.272-0.214,2.435-0.719,3.467-1.406C25.353,31.175,25,32.545,25,34
    c0,2.297,0.868,4.387,2.285,5.977C25.307,40.632,23.198,41,21,41C9.954,41,1,32.046,1,21S9.954,1,21,1s20,8.954,20,20
    c0,2.198-0.368,4.307-1.023,6.285C38.387,25.868,36.297,25,34,25z M25.5,21h-2.25c-0.414,0-0.75-0.336-0.75-0.75
    c0-0.414,0.336-0.75,0.75-0.75h2.25V18h-2.25c-0.414,0-0.75-0.336-0.75-0.75s0.336-0.75,0.75-0.75h2.25V15h-2.25
    c-0.414,0-0.75-0.336-0.75-0.75c0-0.414,0.336-0.75,0.75-0.75h1.974c-0.62-1.744-2.268-3-4.225-3c-1.956,0-3.604,1.256-4.224,3
    h1.975c0.414,0,0.75,0.336,0.75,0.75c0,0.414-0.336,0.75-0.75,0.75H16.5v1.5h2.25c0.414,0,0.75,0.336,0.75,0.75S19.164,18,18.75,18
    H16.5v1.5h2.25c0.414,0,0.75,0.336,0.75,0.75c0,0.414-0.336,0.75-0.75,0.75H16.5v1.5c0,2.485,2.015,4.5,4.5,4.5
    c2.485,0,4.5-2.015,4.5-4.5V21z M34,27c3.866,0,7,3.134,7,7s-3.134,7-7,7s-7-3.134-7-7S30.134,27,34,27z M34,39c2.761,0,5-2.239,5-5
    s-2.238-5-5-5c-2.761,0-5,2.239-5,5S31.239,39,34,39z M33,30.969h2v2h2v2h-2v2h-2v-2h-2v-2h2V30.969z"/>
</g>
</svg>

CSS Template Variables

Great rewrite - brilliant to see all the added options!

I was wondering what all the available variables were within the css template and if this can be found somewhere?

Symbol mode and CSS

It looks like defs and symbols mode doesn't generate CSS. If using symbols mode, the snippet looks like this:

<svg class="icon"><use xlink:href="#icon_comments"></use></svg>

My problem is that I need to set dimensions on the svg tag to correctly size the icon. Can gulp-svg-sprites generate a stylesheet when in symbols mode to set dimensions? Something like:

.icon.comments {
  height: 16px;
  width: 16px;
}

And then use with:

<svg class="icon comments"><use xlink:href="#icon_comments"></use></svg>

I design my SVG icons at the intended height/width, and it would be nice to apply that through a class by default. Thanks!

Feature: option to remove fill from sprites.svg

One of the advantages of using inline SVG (by Ajaxing in the sprites.svg file) is that the elements are styleable using pseudo class selectors eg ::hover and ::active. See here for examples:

http://growdigital.org/test-ajax-svg-icons/
http://codepen.io/sol0mka/pen/80187d6000795e8cfd104486861a801e

It may be good to have an option to remove fills and strokes from all elements (although that does make generating PNG fallbacks a bit more problematic…), possibly by adapting SVGO plugin along these lines:

https://github.com/svg/svgo/blob/master/plugins/removeUselessStrokeAndFill.js

SVG Symbol output

Is there a way to rename the .svg file when using symbols mode? I'm try to rename the file to something like ("sprite-symbols.svg") etc... also when using symbols mode, what is the best way to include the .svg file in the header of a Wordpress site. Currently I'm using "" however I'm not certain that is the bed t method.

Thanks,
Jack

Minimal font-size in Chrome is 12px by default

Not sure how this is supposed to work with font-size scaling. Chrome for example has minimal 12px font-size by default so the rendered icons look cropped (right and bottom edges are cut off): https://dl.dropboxusercontent.com/spa/1dqminp255vakv6/cgu20ie6.png

When I go to (Chrome) settings and set the minimal font-size to 10px it works as intended, but I leave it on 12px default purposely always, including when developing since this will be the default behaviour for most users.

I saw your plan to add the option to change the base font-size, but I'm not sure if this really is the way to go. Different clients / devices / user's preference (visually impaired) can influence this issue regardless of our "safe size asumptions" and then the sprite breaks again without any way for us to know or affect this.

Ability to disable path merging

First off, awesome module. We're using it in a production site and we're loving it.

We're hoping we can get an option to disable the path merging that svgo offers. Currently gulp-svg-sprites/svgo would combine the following paths into one path. This is not always ideal since you lose the ability to style individual paths with CSS.

In:

<g>
  <path d="foo">
  <path d="bar"> 
  <path d="baz">
</g>

Out:

<g>
  <path d="foo bar baz">
</g>

SVG Discrepancies in Safari with Ems

[Note: I've written this through the day as i've been experimenting things. There is sort of a conclusion at the end, making this an issue as a) a place to make a note and b) just incase i'm being stupid!]

I'm not sure where this is coming from (my code or the plugin) but posting here in the hope that someone can help me debug as i've got to the point where i'm punching my colleagues with anger! 😄

It is vaguely related to the issue I opened and closed this morning #42

When I generated the sprite with version pre v1 and specified the background size and positioning in ems (working them out manually), the sprite worked correctly cross browser.

With v1 I can amazingly make a sprite map so there is no manual work involved. However, the generation in the sprite is a bit different to the previous version, and doesn't seem to want to play well in Safari - with the positioning and sizes generated using a template.

If i generate the sprite with the older version, it seems the spacing is slightly different, despite being set to 5 in both cases (e.g. in the older one, there was 5px gap, in the new one it appears there is 5px all the way round - which would account for #37).

I have tried to replicate the original sprite construction using templates, but still no joy. Below are some screenshots of what I am experiencing

How it should look:

screen shot 2014-08-04 at 11 35 31

How it looks in Safari when set to horizontal:

screen shot 2014-08-04 at 11 35 11

How it looks in Safari when set to vertical:

screen shot 2014-08-04 at 11 36 13

Isolating it in Codepen shows that Safari squashes the sprite a little bit - it might have a background size bug when using em units? It lines up on the right hand side (compared to the png & px equivalent) but the left is indented somewhat.

Update:

It is very weird - using diagonal layout resolves the problem. It makes a bigger sheet, but having a vertical or horizontal layout seems to break front-end with miss aligned icons.

In conclusion, this isn't really an issue as such, but confusing nonetheless!


This is my gulpfile, template and mixins if anyone is curious:

https://gist.github.com/mikestreety/fac6dd7c8c933ea871e3

Can gulp-clean devDependency be removed?

I noticed that you're using the deprecated gulp-clean instead of its replacement, gulp-rimraf. I can't figure out where it is being used, though, so I was wondering if the dependency should just be removed instead of updated?

Symbols mode *and* custom filename?

I don't seem to be able to get symbols mode and a custom filename:

gulp.task('sprite', function () {
  return gulp.src(paths.icons)
    .pipe(svgSprite({
      preview: false,
      mode: "symbols",
      svg: {
        sprite: "sprite.svg"
      }
    }))
    .pipe(gulp.dest("tmp/sprites"))
});

This outputs tmp/sprites/svg/symbols.svg.

If I comment out symbols mode, I get tmp/sprites/sprite.svg

No big shakes, just wondering if this is supposed to happen?

IDs from filenames

It would be more semantic / useful to have the ID's of the resultant graphics inside the SVG sprite to be the same as those of the original filenames, the same way that grunt-svgstore does. Then you could follow the workflow described in Chris Coyier's article - i.e. you have a folder of individual svg icons and gulp automatically generates a sprite from them so that you can include the sprite code directly in your HTML then reference the icons by name below.

For example, I currently have an icon arrow-right.svg. After running it through gulp-svg-sprites it might look like this:

<path d="M4.131 8.962c-.434-.429-1.134-.429-1.566 0-.432.427-.432 1.122 0 1.55l12.653 12.528c.434.429 1.133.429 1.566 0l12.653-12.528c.432-.429.434-1.122 0-1.55s-1.136-.429-1.566-.002l-11.87 11.426-11.869-11.424z"/><g transform="translate(32)" id="svg-id-1">

When I include the sprite after the opening body tag, and want to place an icon further down the page, I would do so like this:

<svg viewBox="0 0 100 100" class="icon icon-arrow-right">
    <use xlink:href="#svg-id-1"></use>
</svg>

Here I have to reference #svg-id-1 rather than “arrow-right”. Every time I want to place an icon, especially if I have lots of icons, I would have to open the sprite file and try and work out the ID for the icon I want.

Making this change would still allow people to use the generated sprite.css file and use the sprite as background images, but would also allow people to use the sprite without the CSS, which would allow a bit more flexibility in terms of what you can do with the icons (animating, styling, sizing etc.).

Feature - No preview

With my setup a preview html file isn't required and doesn't work as the gnererated CSS file I use is a LESS file with a variable.
Right now after the task I have to delete the file. It's be nice to have a config option to disable the preview file.

Namespaces are lost on svg elements causing errors

I have a couple icons that contain some non-standard namespaces (xmlns:sketch). When I attempt to convert these, the resultant SVG sprite no longer has those namespaces and the overall SVG is invalid. The result is that the gulp process just hangs while PhantomJS is trying to open an invalid SVG without any decent error messages.

Seems like the library might be able to use a regex to find any namespaces on the root svg element and append those to the wrapper on the sprite sheet. Or, svgo might be able to remove these editor namespaces from the svg prior to the sprite generation?

Ability to specify the sort order of the original sprites.

The plugin inserts the original sprites using their name, which means they're sorted alphabetically. I want to be able to specify the order. In my project I've tried to use different source folders, like so:

return gulp.src(['./img/sprites/general/.svg',
'./img/sprites/icons/
.svg',
'./img/sprites/socials/.svg',
'./img/sprites/clients/
.svg',
'./img/sprites/repeaters/*.svg'])

but the plugin still orders the original sprites by filename.

Silent Failure When Attempting to Import 600+ SVGs

The plugin fails silently when a large number of SVGs are passed in. Tried spriting 600+ with no resultant output, but a small number (I tried 3) works great. When I say "no resultant output" I mean the CSS file, sprited SVG file, and test HTML file are all created, but empty.

Is it possible to apply display size scaling factor?

I have larger SVG files (114px) which are then scaled down to 14px. Is there a way to include the resulting factor somewhere in the configuration? If not, any ideas how I could solve this issue with a work-around?

Custom SVG Template - Invert background position

I am trying to build up a custom SVG template to try and replicate what was generated pre v1. This is because when using ems to position the sprite, all browsers love it except chrome. There was something in the way the older sprite (with <g> instead of <svg> that chrome liked).

So far I have this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
<svg baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" width="{swidth}" height="{sheight}" preserveAspectRatio="xMaxYMax meet" viewBox="0 0 {swidth} {sheight}">
{#svg}
    <g id="{name}"  transform="translate({positionX},{positionY})">
        {raw|s}
    </g>
{~n}{/svg}
</svg>

All i need to do is invert the polarity of the background positions on the transforms and it works perfectly. I'm struggling to do this - any pointers?

Alternatively, is there anyway I can get it to generate the "old" sprite way?

Thanks as always!

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.