Closed Jos512 closed 7 years ago
We built non-CSS templates that expose variables and mixins to support this kind of behavior. Here's an example with SCSS:
gulpfile.js:
gulp.task('build-sprite', function buildSpriteFn () {
// Generate our common spritesheet and SCSS variables
return gulp.src('public/static/icons/sprites/*.png')
.pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.scss' // Note the `.scss` extension
}))
.pipe(gulp.dest('deploy/static/css-sprite-test/'));
});
gulp.task('build-css', function buildCssFn () {
// Generate our multiple stylesheets
return gulp.src('public/static/*.scss') // Load post.scss and page.scss
.pipe(gulp.dest('deploy/static/css-sprite-test/')); // Outputs post.css and page.css
});
post.scss and page.css:
@import "../../deploy/static/css-sprite-test/sprite.scss";
@include sprites($spritesheet-sprites);
// More post.css/page.css
Thanks for your quick comment and example, much appreciated!
I struggle with the following: for my sites, I use different CSS files so that redundant CSS rules are kept to a minimum (to aid page speed).
But gulp.spritesmith 'forces' me to use one CSS file for a sprite. When deploying, I'll then have to merge that CSS file into each individual CSS file, giving a lot of unnecessary rules.
Is there perhaps a way to generate one sprite but different CSS files?
My failed attempt for this is the following:
Any insights appreciated!