Skip to content

Instantly share code, notes, and snippets.

@frankrausch
Last active Dec 16, 2017
Embed
What would you like to do?
Compile individual SVG icons into one SASS file as data URIs
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