Gathering detailed insights and metrics for grunt-svg-sprite
Gathering detailed insights and metrics for grunt-svg-sprite
Gathering detailed insights and metrics for grunt-svg-sprite
Gathering detailed insights and metrics for grunt-svg-sprite
SVG sprites & stacks galore — Grunt 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
npm install grunt-svg-sprite
v2.0.2
Published on 16 Mar 2023
v2.0.1
Published on 12 Nov 2022
v2.0.0
Published on 27 Sept 2022
1.5.0 Compatibility release (2018-09-18)
Published on 18 Sept 2018
1.4.1 Compatibility release (2018-09-18)
Published on 18 Sept 2018
1.4.0 Compatibility release (2019-03-17)
Published on 17 Mar 2018
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
128 Stars
203 Commits
11 Forks
7 Watching
4 Branches
6 Contributors
Updated on 12 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.2%
1,127
Compared to previous day
Last week
-1.9%
7,008
Compared to previous week
Last month
56.3%
31,865
Compared to previous month
Last year
16%
249,511
Compared to previous year
4
1
6
grunt-svg-sprite is a Grunt 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 Grunt specific installation and configuration aspects. For a full list of features and options, please see the svg-sprite manual.
This plugin requires Grunt >=0.4.5
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:
1npm install grunt-svg-sprite --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
1grunt.loadNpmTasks('grunt-svg-sprite');
In your project's Gruntfile, add a section named svg_sprite
to the data object passed into grunt.initConfig()
.
1grunt.initConfig({
2 svg_sprite: {
3 options: {
4 // Task-specific options go here.
5 },
6 your_target: {
7 // Target-specific file lists and/or options go here.
8 },
9 }
10});
The task-specific options
are optional and affect all defined targets. You may define as many targets (your_target
) as you want.
In the simplest case an «svg_sprite» target looks like this:
1your_target: { 2 src: ['path/to/assets/**/*.svg'], 3 dest: 'path/to/css/dir', 4 options: { 5 // Target-specific options 6 } 7},
However, as the path/to/assets
would become part of the shape IDs, you will most likely want to add a working directory in most cases:
1your_target: { 2 expand: true, 3 cwd: 'path/to/assets', 4 src: ['**/*.svg'], 5 dest: 'path/to/css/dir', 6 options: { 7 // Target-specific options 8 } 9},
As target-specific options you may provide a main configuration object as described in the svg-sprite manual. Configuration-wise, svg-sprite and grunt-svg-sprite differ only in one respect:
Type: String
Default value: '.'
Instead of being nested inside the options
object, svg-sprite's dest
property gets promoted one level up and becomes part of the Grunt target configuration itself (see examples above).
In this very basic example, mostly default settings will be applied to create a traditional CSS sprite (bundle of SVG sprite and CSS stylesheet).
1grunt.initConfig({
2 svg_sprite: {
3 basic: {
4 // Target basics
5 expand: true,
6 cwd: 'assets',
7 src: ['**/*.svg'],
8 dest: 'out',
9 // Target options
10 options: {
11 mode: {
12 css: { // Activate the «css» mode
13 render: {
14 css: true // Activate CSS output (with default options)
15 }
16 }
17 }
18 }
19 }
20 }
21});
The following files and directories are created:
1out/ 2├─ css/ 3│ ├─ sprite.css 4│ ├─ svg/ 5│ │ ├─ 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:
1grunt.initConfig({
2 svg_sprite: {
3 complex: {
4 // Target basics
5 expand: true,
6 cwd: 'assets',
7 src: ['**/*.svg'],
8 dest: 'out',
9 // Target options
10 options: {
11 shape: {
12 dimension: { // Set maximum dimensions
13 maxWidth: 32,
14 maxHeight: 32
15 },
16 spacing: { // Add padding
17 padding: 10
18 },
19 dest: 'out/intermediate-svg' // Keep the intermediate files
20 },
21 mode: {
22 view: { // Activate the «view» mode
23 bust: false,
24 render: {
25 scss: true // Activate Sass output (with default options)
26 }
27 },
28 symbol: true // Activate the «symbol» mode
29 }
30 }
31 }
32 }
33});
The following files and directories are created:
1out/ 2├─ intermediate-svg 3│ ├─ weather-clear.svg 4│ ├─ weather-snow.svg 5│ ├─ weather-storm.svg 6├─ symbol/ 7│ ├─ svg/ 8│ ├─ sprite.symbol.svg 9├─ view/ 10│ ├─ sprite.scss 11│ ├─ svg/ 12│ ├─ sprite.view.svg
For more advanced features like
please refer to the svg-sprite manual.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Please refer to the GitHub releases for a complete release history.
Copyright © 2018 Joschi Kuphal joschi@kuphal.net / @jkphl. grunt-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.
No vulnerabilities found.
No security vulnerabilities found.