From a0f74506d29d8cd7b92ede7c747165e6cdcac30b Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Mon, 11 Apr 2016 15:49:10 -0400 Subject: [PATCH] Added 'grunt-svg-sprite' plugin The plugin replaces 'svgmin' and 'svgstore' with an all-in-one and highly flexible solution for managing SVG assets. Changes: - Deleted 'assets/images/sprite/', SVG images can live anywhere within the source image directory; - When compiled to 'www/assets/images/sprite.svg', the plugin generates an HTML file in 'assets/images/sprite.symbol.html' that serves as an index of the spritesheet's contents; - A separator ("--") is used when traversing a directory structure for the symbol ID (e.g, 'sprite.svg#icons--social--twitter'); --- Gruntfile.js | 1 - assets/images/{sprite => }/.gitkeep | 0 build/grunt/config/aliases.json | 3 +-- build/grunt/config/svg_sprite.js | 29 +++++++++++++++++++++++++++++ build/grunt/config/svgmin.js | 22 ---------------------- build/grunt/config/svgstore.js | 8 -------- build/grunt/config/watch.js | 2 +- package.json | 3 +-- www/assets/images/sprite.svg | 1 - 9 files changed, 32 insertions(+), 37 deletions(-) rename assets/images/{sprite => }/.gitkeep (100%) create mode 100644 build/grunt/config/svg_sprite.js delete mode 100644 build/grunt/config/svgmin.js delete mode 100644 build/grunt/config/svgstore.js delete mode 100644 www/assets/images/sprite.svg diff --git a/Gruntfile.js b/Gruntfile.js index 53197a1..cc7d883 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -32,5 +32,4 @@ module.exports = function (grunt) } } }); - }; diff --git a/assets/images/sprite/.gitkeep b/assets/images/.gitkeep similarity index 100% rename from assets/images/sprite/.gitkeep rename to assets/images/.gitkeep diff --git a/build/grunt/config/aliases.json b/build/grunt/config/aliases.json index 694e29d..ce18eb0 100644 --- a/build/grunt/config/aliases.json +++ b/build/grunt/config/aliases.json @@ -17,8 +17,7 @@ "browserify:prod", "concat:prod", "uglify", - "svgstore", - "svgmin", + "svg_sprite", "notify:build" ], diff --git a/build/grunt/config/svg_sprite.js b/build/grunt/config/svg_sprite.js new file mode 100644 index 0000000..0bc2399 --- /dev/null +++ b/build/grunt/config/svg_sprite.js @@ -0,0 +1,29 @@ +module.exports = { + options : { + svg: { + xmlDeclaration : false, + namespaceIDs : true, + doctypeDeclaration : false, + cleanupNumericValues : true, + removeTitle : true, + removeDesc : true + } + }, + prod: { + expand : true, + cwd : '<%= paths.img.src %>', + src : [ '**/*.svg', '!sprite.svg' ], + dest : '<%= paths.img.dist %>', + options : { + mode: { + symbol: { + dest : '.', + sprite : 'sprite.svg', + example : { + dest: '../../../build/sprite.symbol.html' + } + } + } + } + } +} diff --git a/build/grunt/config/svgmin.js b/build/grunt/config/svgmin.js deleted file mode 100644 index 4f24572..0000000 --- a/build/grunt/config/svgmin.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = { - options: { - plugins: [ - { removeViewBox: false }, - { cleanupIDs: false }, - { convertPathData: false }, - { mergePaths: false }, - { convertShapeToPath: false }, - { cleanupNumericValues: false }, - { convertTransform: false }, - { removeUselessStrokeAndFill: false }, - { removeTitle: true }, - { removeDesc: true } - ] - }, - dist: { - expand : true, - cwd : '<%= paths.img.dist %>', - src : '*.svg', - dest : '<%= paths.img.dist %>' - } -}; diff --git a/build/grunt/config/svgstore.js b/build/grunt/config/svgstore.js deleted file mode 100644 index 7e52d7e..0000000 --- a/build/grunt/config/svgstore.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - options: {}, - prod: { - files: { - '<%= paths.img.dist %>/sprite.svg': [ '<%= paths.img.src %>/sprite/*.svg' ] - } - } -}; diff --git a/build/grunt/config/watch.js b/build/grunt/config/watch.js index e5403f6..e5a5993 100644 --- a/build/grunt/config/watch.js +++ b/build/grunt/config/watch.js @@ -13,7 +13,7 @@ module.exports = { }, svg: { files: [ '<%= paths.img.src %>/**/*.svg' ], - tasks: [ 'svgstore', 'notify:svg' ] + tasks: [ 'svg_sprite', 'notify:svg' ] }, tasks: { options: { diff --git a/package.json b/package.json index 6e83798..bb0c768 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ "grunt-phplint": "0.0.0", "grunt-postcss": "0.0.0", "grunt-sass": "0.0.0", - "grunt-svgmin": "0.0.0", - "grunt-svgstore": "0.0.0", + "grunt-svg-sprite": "0.0.0", "load-grunt-config": "0.0.0", "postcss-banner": "0.0.0", "svg4everybody": "0.0.0" diff --git a/www/assets/images/sprite.svg b/www/assets/images/sprite.svg deleted file mode 100644 index 5fda422..0000000 --- a/www/assets/images/sprite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file