Hi, I just want to share my svg workflow since it look a little bit different.
I keep all my svg’s in:
assets/images/icons/icon-name.svg
I use svg-injector.js, wich injects the files with JS, and make them cachable. You can install it by running:
bower install svg-injector --save
Sage just imports the script in main.js automagically.
Then I use gulp-svgmin to minify the svg’s, removing comments from sketch/illustrator and such. You can install the plugin with npm like so:
npm install gulp-svgmin --save-dev
Then I make a task in Sage’s gulpfile.js, my task look like this:
// ### Svg
// ´gulp svg´ - Compress SVG files
gulp.task('svg', function () {
return gulp.src(globs.images)
.pipe(svgmin())
.pipe(gulp.dest(path.dist + 'images'));
});
Then offcourse I’ll put it in the images part of the watch task aswell:
gulp.watch([path.source + 'images/**/*'], ['images', 'svg']);
And in the build task:
gulp.task('build', function(callback) {
runSequence('styles',
'scripts',
['fonts', 'images', 'svg'],
callback);
});
Then in the main js file you have to initialize the script:
var mySVGsToInject = document.querySelectorAll('img.svg-icon');
new SVGInjector(mySVGsToInject);
I embed my svg’s like this in the php:
<img class="svg-icon" src="<?php echo get_template_directory_uri(); ?>/dist/images/icons/menu.svg">
Guess you could beautify that with a variable to the path
Hope it helps!