
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
gulp-svg-sprite-plus
Advanced tools
SVG sprites & stacks galore — Gulp plugin wrapping around svg-sprite that reads in a bunch of SVG files, optimizes them and creates SVG sprites and CSS resources in various flavours
This package is forked from Joschi Kuphal's gulp-svg-sprite, I make it to support "fill", so that we can use css to control the color of svg icons, please set the color to black(mean pure black, #000, other colors will remain.) if you want to change it in any stylesheet files.
===============
is a Gulp plugin wrapping around svg-sprite which takes a bunch of SVG files, optimizes them and bakes them into SVG sprites of several types:
<view>
elements, useful for foreground images as well,<defs>
element,<symbol>
elementThis document covers only gulp specific installation and configuration aspects. For a full list of features and options, please see the svg-sprite manual.
First, install gulp-svg-sprite
as a development dependency:
npm install --save-dev gulp-svg-sprite
Then, add it to your gulpfile.js
:
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite');
gulp.src('assets/*.svg')
.pipe(svgSprite( /* ... Insert your configuration here ... */ ))
.pipe(gulp.dest('out'));
NOTICE: By default, svg-sprite doesn't send any files downstream unless you configure it. There are tons of options available — please see below for some basic examples. Also, you should possibly take care of errors that might occur.
As options
argument you may provide a main configuration object as described in the svg-sprite manual. Configuration-wise, svg-sprite and gulp-svg-sprite differ only in one respect:
Type: String
Default value: '.'
With Gulp, there is no need to specifiy a main output directory, as the generated files are piped to the next step of the running task anyway. The options.dest
value (if given) is simply ignored.
In this very basic example, mostly default settings will be applied to create a traditional CSS sprite (bundle of SVG sprite and CSS stylesheet).
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite'),
// Basic configuration example
config = {
mode : {
css : { // Activate the «css» mode
render : {
css : true // Activate CSS output (with default options)
}
}
}
};
gulp.src('**/*.svg', {cwd: 'assets'})
.pipe(svgSprite(config))
.pipe(gulp.dest('out'));
The following files and directories are created:
out
`-- css
|-- sprite.css
`-- svg
`-- sprite.css-495d2010.svg
The cryptical looking part in the SVG's file name is the result of svg-sprite's cache busting feature which is enabled by default for CSS sprites. We'll turn this off in the next example.
The following example is a little more complex:
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite'),
// More complex configuration example
config = {
shape : {
dimension : { // Set maximum dimensions
maxWidth : 32,
maxHeight : 32
},
spacing : { // Add padding
padding : 10
},
dest : 'out/intermediate-svg' // Keep the intermediate files
},
mode : {
view : { // Activate the «view» mode
bust : false,
render : {
scss : true // Activate Sass output (with default options)
}
},
symbol : true // Activate the «symbol» mode
}
};
gulp.src('**/*.svg', {cwd: 'assets'})
.pipe(svgSprite(config))
.pipe(gulp.dest('out'));
The following files and directories are created:
out
|-- intermediate-svg
| |-- weather-clear.svg
| |-- weather-snow.svg
| `-- weather-storm.svg
|-- symbol
| `-- svg
| `-- sprite.symbol.svg
`-- view
|-- sprite.scss
`-- svg
`-- sprite.view.svg
Errors might always happen — maybe there are some corrupted source SVG files, the default SVGO plugin configuration is too aggressive or there's just an error in svg-sprite's code. To make your tasks more robust, you might consider using plumber and adding your custom error handling:
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite'),
plumber = require('gulp-plumber'),
// Basic configuration example
config = {
mode : {
css : {
render : {
css : true
}
}
}
};
gulp.src('**/*.svg', {cwd: 'assets'})
.pipe(plumber())
.pipe(svgSprite(config))
.on('error', function(error){
/* Do some awesome error handling ... */
})
.pipe(gulp.dest('out'));
For more advanced features like
please refer to the svg-sprite manual.
Please refer to the changelog for a complete release history.
Copyright © 2015 Joschi Kuphal joschi@kuphal.net / @jkphl. svg-sprite is licensed under the terms of the MIT license. The contained example SVG icons are part of the Tango Icon Library and belong to the Public Domain.
1.1.2 Bugfix release (2015-04-22)
FAQs
SVG sprites & stacks galore — Gulp plugin wrapping around svg-sprite that reads in a bunch of SVG files, optimizes them and creates SVG sprites and CSS resources in various flavours
We found that gulp-svg-sprite-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.