Created
April 1, 2014 13:23
-
-
Save stugoo/9913904 to your computer and use it in GitHub Desktop.
Grunt, scss and hbs for turning svgs into icons and pngs,
This file contains 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
// requires | |
/* | |
* https://github.com/filamentgroup/grunticon | |
* https://www.npmjs.org/package/grunt-text-replace | |
*/ | |
'use strict'; | |
module.exports = function (grunt) { | |
// Load grunt tasks automatically | |
require('load-grunt-tasks')(grunt); | |
// Time how long tasks take. Can help when optimizing build times | |
require('time-grunt')(grunt); | |
// Define the configuration for all the tasks | |
grunt.initConfig({ | |
grunticon: { | |
svgicons: { | |
files: [{ | |
expand: true, | |
cwd: 'images/svg-icons', | |
src: ['*.svg', '*.png'], | |
dest: "styles/scss/icons/generated" | |
}], | |
options: { | |
svgo: true, | |
pngcrush: true, | |
cssprefix: '%icon-', | |
datasvgcss: '_icons-data-svg.scss', | |
datapngcss: '_icons-data-png.scss', | |
urlpngcss: '_icons-fallback.scss', | |
template: "styles/scss/icons/icon-template-css.hbs" | |
} | |
} | |
}, | |
replace: { | |
nosvgicons: { | |
src: [ | |
'styles/scss/icons/generated/_icons-fallback.scss' | |
], | |
overwrite: true, | |
replacements: [{ | |
from: '%icon-', | |
to: '%nosvg-icon-' | |
}] | |
} | |
} | |
}); | |
grunt.registerTask('svgicons',[ | |
'grunticon:svgicons', | |
'replace:nosvgicons' | |
]); |
This file contains 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
/* ========================================================================== | |
= Icons | |
========================================================================== */ | |
// = firstly import generated icons | |
@import "generated/icons-data-svg"; | |
@import "generated/icons-fallback"; | |
//declare global icon usage | |
[class^="icon-"], | |
[class*=" icon-"] { | |
speak: none; | |
font-weight: normal; | |
font-variant: normal; | |
text-transform: none; | |
font-style: normal; | |
-webkit-font-smoothing: antialiased; | |
font-smoothing: antialiased; | |
background:transparent no-repeat 50% 50% / contain; | |
} | |
// = develop the mixin for the files | |
@mixin grunticon($name) { | |
width: 100px; | |
height: 100px; | |
&, | |
.no-svg &{ | |
@extend %nosvg-icon-#{$name}; | |
} | |
.svg & { | |
@extend %icon-#{$name}; | |
} | |
} | |
// = Declare all icons based on svg-icon file name | |
.icon-chevron { | |
@include grunticon(chevron); | |
} | |
.icon-logo { | |
@include grunticon(logo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment