Grunt plugin to create SVG sprites with PNG fallbacks at needed sizes
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install dr-grunt-svg-sprites --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('dr-grunt-svg-sprites');
In your project's Gruntfile, add a section named svg_sprites
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
svg_sprites: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: Object
Type: String
Optional. Source path of svg elements to composite sprite-elements.
Type: String
Source path of the svg elements to make up a sprite.
Type: String
Destination path of the generated sprite images.
Type: String
Destination path of the generated stylesheet.
Type: Object
Type: String
Default value: ''
Optional. Stylesheet
Type: String
Default value: 'css'
Optional. Stylesheet filetype suffix.
Type: Number
Defines unit size of the grid the sprite elements snap to.
Type: String
Defines the default size
Type: Object
A hash of size labels and values (Number
).
Type: Object
{spriteName}
grunt.initConfig({
svg_sprites: {
paths: {
spriteElements: "img/_source/svg-logos",
sprites: "img/_source/sprites",
css: "css/shared",
},
},
})
grunt.initConfig({
svg_sprites: {
paths: {
elements: "img/_source/svg-logo-elements",
spriteElements: "img/_source/svg-logos",
sprites: "img/_source/sprites",
css: "css/shared",
},
},
})