PostCSS plugin to construct SVG sprite.
Input
@svgsprite common;
Output
.demo_common {
background: url("../sprite/common.svg") left top no-repeat;
display: inline-block;
overflow: hidden;
font-size: 0;
line-height: 0;
vertical-align: top;
}
.demo_common_AddMemberSmallGray {
width: 14px;
height: 14px;
background-position: -74px -26px;
}
.demo_common_ArrowGrayDown6h {
width: 10px;
height: 6px;
background-position: -44px -30px;
}
Work with Gulp
let gulp = require('gulp'),
postcss = require('gulp-postcss'),
svgSprite = require('./index.js');
gulp.task('sprite', function () {
return gulp.src('./example/src/css/*.css')
.pipe(postcss([svgSprite({
imagePath: './example/src/svg',
spriteOutput: './example/dist/sprite',
styleOutput: './example/dist/css',
nameSpace: 'demo_',
})]))
.pipe(gulp.dest('./example/dist/css'));
});
Relative path to the folder that svgs are stored.
Relative path to the folder that will keep your output stylesheet(s).
Relative path to the folder that will keep your output sprite(s).
NameSpace(Prefix) of the class name of each svg.
Separator between css selector's 'block' and 'element'. In this plugin. 'block' is equal to file dirname or dynamic one, 'element' is the base name of file.
See PostCSS docs for examples for your environment.