I am using gulp.spritesmith to automate sprite image and css generation. All works good except the generated css is haivng "icon-" prefix. I don't want to add this prefix as I have existing HTML markup and I don't want to change the markup. Following is my gulp task.
'use strict';
var gulp = require('gulp');
var spritesmith = require('gulp.spritesmith');
gulp.task('sprite', function () {
var spriteData =
gulp.src('./sprite/*.*') // source path of the sprite images
.pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.css'
}));
spriteData.img.pipe(gulp.dest("./css")); // output path for the sprite
spriteData.css.pipe(gulp.dest("./css")); // output path for the CSS
});
Following is my generated css.
.icon-icon1 {
background-image: url(sprite.png);
background-position: 0px 0px;
width: 120px;
height: 120px;
}
.icon-icon2 {
background-image: url(sprite.png);
background-position: -120px 0px;
width: 120px;
height: 120px;
}
Please help to supress "icon-".
You can alternatively use the cssSelector
of the library.
cssOpts: {
cssSelector: function (sprite) {
return '.' + sprite.name;
}
}
You can use gulp-replace to remove the "icon-" prefixes.
Last line of your sprite
task would become
spriteData.css
.pipe(replace(/^\.icon-/gm, '.'))
.pipe(gulp.dest("./css"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With