I am looking to simplify the process of generating icons from svg-files while also creating a png-sprite fallback for IE8 support. I am using grunt.js and less.
I was inspired by the implementation on 2gis.ru: (in Russian), where they used technologies such as node.js, npm, grunt.js, and less.
Here is a snippet of code that showcases what I am aiming to achieve:
I have created this template: https://github.com/andrey-hohlov/template-mark-up (don't forget to use 'npm install' after cloning)
However, I am facing an issue in one step:
- Place svg-icons in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/svg-icons
- Put png-icons in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/img/png-icons
- Utilize grunt
- All sprites will be generated in github.com/andrey-hohlov/template-mark-up/tree/master/assets/build/img
- .less files are created in github.com/andrey-hohlov/template-mark-up/tree/master/assets/dev/css/less/mixins/bg-icon/temp using spritesmith, which cannot be modified
Now onto the less files:
- github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/datauri.less contains base64 code for svg icons with class names based on file names, only allowing me to set suffixes and prefixes
- Files like github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/temp/sprite.datauri.less include mixins and variables for creating sprite css for png icons, leveraging the width and height data from svg icons (as the datauri task provides only base64)
- The issue lies in github.com/andrey-hohlov/template-mark-up/blob/master/assets/dev/css/less/mixins/bg-icon/bg-icon.less. There are two mixins - one for svg icons and one for png icons. I need to utilize them with the "filename" parameter to generate css for icons, but I am unsure how to do so. I have left comments in the file.
P.S. I had to remove some URLs due to my lack of reputation. P.P.S. Apologies for any language errors in my explanation :(