sprites.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import config from '../config';
  2. import path from 'path';
  3. import gulp from 'gulp';
  4. import plumber from 'gulp-plumber';
  5. import svgSprite from 'gulp-svg-sprite';
  6. const spriteConfig = {
  7. mode: {
  8. symbol: {
  9. dest: './',
  10. sprite: path.join(
  11. '../',
  12. config.paths.images,
  13. 'sprites.svg'
  14. )
  15. }
  16. },
  17. shape: {
  18. meta: path.join(
  19. config.paths.src,
  20. config.paths.images,
  21. config.paths.sprites,
  22. 'sprites.yaml'
  23. ),
  24. id: {
  25. generator: 'icon--%s'
  26. }
  27. }
  28. };
  29. /**
  30. * Compile svg sprites into single svg file
  31. *
  32. * @param cb: callback handler passed by gulp, signals task completion when called
  33. */
  34. export const sprites = (cb) => {
  35. gulp.src(
  36. path.join(
  37. config.paths.src,
  38. config.paths.images,
  39. config.paths.sprites,
  40. '*.svg'
  41. ))
  42. .pipe(plumber())
  43. .pipe(svgSprite(spriteConfig))
  44. .pipe(gulp.dest(
  45. path.join(
  46. config.paths.dest,
  47. config.paths.assets,
  48. config.paths.images
  49. )
  50. ));
  51. cb();
  52. };