0.3.1 • Published 5 years ago
gulp-svg2string v0.3.1
gulp-svg2string
Convert SVG file to JavaScript string.
THIS PACKAGE IS NO LONGER MAINTAINED
Install
$ npm install --save-dev gulp-svg2string
Usage
var gulp = require('gulp');
var svgstore = require('gulp-svgstore');
var svg2string = require('gulp-svg2string');
gulp.task('default', function() {
return gulp
.src('src/**/*.svg')
.pipe(svgstore({ inlineSvg: true }))
.pipe(svg2string())
.pipe(gulp.dest('dest'));
});
<!DOCTYPE html>
<html lang="en">
<head>
<script src="sprite.js"></script>
</head>
<body>
<!-- SVG sprite include -->
<div
class="svg-placeholder"
style="border: 0; clip: rect(0 0 0 0); height: 1px;
margin: -1px; overflow: hidden; padding: 0;
position: absolute; width: 1px;"
></div>
<script>
document.querySelector('.svg-placeholder').innerHTML = SVG_SPRITE;
</script>
<!-- end SVG sprite include -->
<svg xmlns="http://www.w3.org/2000/svg">
<use xlink:href="#icon"></use>
</svg>
</body>
</html>
Options
The variableName
specifies the name of the sprite variable.
svg2string({
variableName: 'MY_SVG_SPRITE',
});
<script>
document.querySelector('.svg-placeholder').innerHTML = MY_SVG_SPRITE;
</script>