Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. const gulp = require('gulp');
  2. const browserSync = require('browser-sync').create();
  3. const del = require('del');
  4. const runSequence = require('run-sequence');
  5. const responsiveGm = require('gulp-responsive-images');
  6. const imagemin = require('gulp-imagemin');
  7. const reload = browserSync.reload;
  8.  
  9. gulp.task('default', function() {
  10. console.log('Hello World')
  11. });
  12.  
  13. // use GM then move to folder responsive
  14. gulp.task('imagesgm', function() {
  15. return gulp.src('app/images_src/**/*')
  16. .pipe(responsiveGm({
  17. '*.jpg': [{
  18. width: 1600,
  19. suffix: '_large_2x',
  20. quality: 75
  21. }, {
  22. width: 1600,
  23. suffix: '_large_1x',
  24. quality: 50
  25. }, {
  26. width: 600,
  27. height: 400,
  28. crop: 'center',
  29. suffix: '_medium_2x',
  30. quality: 75
  31. }, {
  32. width: 600,
  33. height: 400,
  34. crop: 'center',
  35. suffix: '_medium_1x',
  36. quality: 50
  37. }, {
  38. width: 300,
  39. height: 250,
  40. crop: 'center',
  41. suffix: '_small',
  42. quality: 50
  43. }],
  44. }))
  45. .pipe(gulp.dest('app/responsive/'));
  46. });
  47.  
  48. // use imagemin then move to folder images
  49. gulp.task('imagesmin', () => {
  50. return gulp.src('app/responsive/**/*')
  51. .pipe($.cache($.imagemin()))
  52. .pipe(gulp.dest('app/images/'));
  53. });
  54.  
  55. // copies any images in fixed to images folder
  56. gulp.task('copy-fixed-images', function() {
  57. return gulp.src('./app/images_src/fixed/**/*')
  58. .pipe(gulp.dest('./app/images/'));
  59. });
  60.  
  61. // cleans responsive folder
  62. gulp.task('responsive-tidy', function() {
  63. return del([
  64. './app/responsive/**/*'
  65. ]);
  66. })
  67.  
  68. // combo build task for responsive (gm) and min images
  69. gulp.task('build-images', function(callback) {
  70. runSequence('imagesgm', ['imagesmin', 'copy-fixed-images'],
  71. 'responsive-tidy',
  72. callback);
  73. });
  74.  
  75. // serve to browser (Chrome)
  76. gulp.task('serve', function() {
  77. browserSync.init({
  78. port: 9000,
  79. browser: "google chrome",
  80. server: {
  81. baseDir: "./"
  82. }
  83. });
  84. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement