Last active
December 16, 2017 15:35
-
-
Save frankrausch/107a35fcc2799a868a90101e1d0730af to your computer and use it in GitHub Desktop.
Compile individual SVG icons into one SASS file as data URIs
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
sourceFiles="../assets/icons/*.svg" | |
destFile="../assets/sass/_icons.svg.scss" | |
classPrefix=".icon-" | |
echo "Compiling icons from "$sourceFiles" into "$destFile" …" | |
echo "" > $destFile | |
for fileWithPath in ../assets/icons/*.svg; | |
do | |
contents=$(cat $fileWithPath) | |
contents=$(svgo -s "${contents}") | |
contents=$(php -r "echo rawurlencode('$contents');") | |
filename=${fileWithPath##*/} | |
classname=${filename%.*} | |
scss=${classPrefix}${classname}"{background-image:url('data:image/svg+xml;utf8,"$contents"')}" | |
echo $scss >> $destFile | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment