Advertisement
Gordon___From

Spritesmith laravel example

Apr 2nd, 2017
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://github.com/twolfson/gulp.spritesmith
  2. // Example task with retina setup:
  3. // @1x and @2x should have exact proportions
  4. // otherwise spritesmith throws:
  5. // Error: Normal sprite has inconsistent size with retina sprite.
  6. // details and workaround: https://github.com/twolfson/gulp.spritesmith/issues/57
  7.  
  8. const elixir = require('laravel-elixir');
  9. const Task = elixir.Task;
  10. const gulp = require('gulp');
  11. const spritesmith = require('gulp.spritesmith');
  12. const buffer = require('vinyl-buffer');
  13. const imagemin = require('gulp-imagemin');
  14. const del = require('del');
  15. const merge = require('merge-stream');
  16.  
  17. elixir.extend('makeSprites', function() {
  18.    new Task('makeSprites', function() {
  19.      let spriteData = gulp.src('path_to_source/*.png')
  20.        .pipe(spritesmith({
  21.          retinaSrcFilter: ['path_to_source/*@2x.png'],
  22.          imgName: 'sprite.png',
  23.          retinaImgName: 'sprite@2x.png',
  24.          cssName: 'sprite.less',
  25.          imgPath: 'path_to_use_in_css/sprite.png'
  26.        }));
  27.  
  28.      let imgStream = spriteData.img
  29.        .pipe(buffer())
  30.        .pipe(imagemin())
  31.        .pipe('path_to_source_image_folder');
  32.  
  33.      let cssStream = spriteData.css
  34.        .pipe('path_to_source_less_folder');
  35.  
  36.      return merge(imgStream, cssStream);
  37.   });
  38. });
  39.  
  40. elixir(mix => {
  41.   // ...
  42.   mix.makeSprites();
  43.   //...
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement