Created
November 9, 2015 12:05
-
-
Save scarfacedeb/e972c30b4763b2bd2a92 to your computer and use it in GitHub Desktop.
Grunt task to compile svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To optimize, minify and combine svg files | |
// | |
// Example: | |
// grunt --target="../app/views/public/shared/_svg.html" | |
// grunt --target="../app/views/public/shared/_categories_svg.html" --source="categories/*.svg" | |
// | |
module.exports = function(grunt) { | |
// process argv | |
var target = grunt.option('target') || '../app/views/public/shared/_svg.html'; | |
var source = grunt.option('source') || 'svg/*.svg'; | |
var cleanTarget = 'dist/' + source; | |
var svgStoreDefault = { | |
files: {} | |
}; | |
svgStoreDefault.files[target] = cleanTarget; | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
clean: [cleanTarget],ј | |
svgmin: { | |
options: { | |
plugins: [ | |
{ removeUselessStrokeAndFill: true }, | |
{ transformsWithOnePath: true } | |
] | |
}, | |
dist: { | |
files: [{ | |
expand: true, | |
src: [source], | |
dest: 'dist/', | |
ext: '.svg' | |
}] | |
} | |
}, | |
svgstore: { | |
options: { | |
prefix : 'icon-', | |
symbol: { | |
viewBox: '0 0 32 32' | |
}, | |
includedemo: false, | |
cleanup: true | |
}, | |
default: svgStoreDefault | |
}, | |
watch: { | |
svg: { | |
files: [source], | |
tasks: ['default'] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-svgstore'); | |
grunt.loadNpmTasks('grunt-svgmin'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
// Default task(s). | |
grunt.registerTask('default', ['clean', 'svgmin', 'svgstore']); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "svg_task", | |
"description": "Svg-related tasks for nonpandoras.com", | |
"version": "0.1.0", | |
"devDependencies": { | |
"grunt": "~0.4", | |
"grunt-svgstore": "~0.5", | |
"grunt-svgmin": "~2.0", | |
"grunt-contrib-watch": "~0.6", | |
"grunt-contrib-clean": "~0.6" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment