Skip to content

Instantly share code, notes, and snippets.

@ahultgren
Last active December 26, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahultgren/7138450 to your computer and use it in GitHub Desktop.
Save ahultgren/7138450 to your computer and use it in GitHub Desktop.
A template to generate a retina/high-res less spritesheet using grunt-spritesmith _without_ using both hi/low res images. Also it generates a bit less bloated rules than default. You might want to modify the template (eg classname and selector) depending on how you prefer to name stuff.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
sprite: {
icons: {
src: 'img/icons/*.{png,jpg,gif}',
destImg: 'img/icons.png',
destCSS: 'less/general/icons.less',
algorithm: 'binary-tree',
cssTemplate: 'path/to/icon.template.mustache'
}
}
});
// npm tasks
grunt.loadNpmTasks('grunt-spritesmith');
// Default task.
grunt.registerTask('default', ['sprite']);
};
.icon {
background-image: url({{{items.0.escaped_image}}});
background-size: {{items.0.px.total_width}}/2 auto;
{{#items}}
&.{{name}} {
background-position: {{px.offset_x}}/2 {{px.offset_y}}/2;
width: {{px.width}}/2;
height: {{px.height}}/2;
}
{{/items}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment