Answer the question
In order to leave comments, you need to log in
How to generate svg files into a sprite so that it can be inserted via html?
Good afternoon
What needs to be installed so that the svg files are generated in one sprite and I can insert them in this form into the html code:
Earlier, I installed npm i gulp.spritesmith and prescribed the task:
gulp.task('sprite', function () {
var spriteData = gulp.src('app/img/icon/*.png').pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.scss'
}));
return spriteData.pipe(gulp.dest('app/sprite/'));
});
Answer the question
In order to leave comments, you need to log in
I am using gulp svgstore for svg sprites.
var svgstore = require('svgstore');
var rename = require("gulp-rename");
gulp.task('svg-sprite', function(){
return gulp.src(['dist/img/svg/icon/**/*.svg', '!dist/svg/icon/sprite.svg'])
.pipe(svgstore({
inlineSvg: true
}))
.pipe(rename('sprite.svg'))
.pipe(gulp.dest('dist/img/svg/icon'))
});
<svg>
<use xlink:href="img/svg/icon/sprite.svg#id_свг_без_формата"></use>
</svg>
Например:
<svg>
<use xlink:href="img/svg/icon/sprite.svg#icon-top3"></use>
</svg>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question