gulpfile.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var gulp = require('gulp');
  2. var browserSync = require('browser-sync');
  3. var sass = require('gulp-sass');
  4. var reload = browserSync.reload;
  5. var through = require("through2");
  6. /**
  7. * A slow task
  8. */
  9. gulp.task('slow1', function () {
  10. return gulp.src('./app/*.html')
  11. .pipe(slowStream());
  12. });
  13. /**
  14. * Another Slow task
  15. */
  16. gulp.task('slow2', function () {
  17. return gulp.src('./app/*.html')
  18. .pipe(slowStream());
  19. });
  20. /**
  21. * Separate task for the reaction to a file change
  22. */
  23. gulp.task('html-watch', ['slow1', 'slow2'], reload);
  24. /**
  25. * Sass task for live injecting into all browsers
  26. */
  27. gulp.task('sass', function () {
  28. return gulp.src('./app/scss/*.scss')
  29. .pipe(sass())
  30. .pipe(gulp.dest('./app/css'))
  31. .pipe(reload({stream: true}));
  32. });
  33. /**
  34. * Serve and watch the html files for changes
  35. */
  36. gulp.task('default', function () {
  37. browserSync({server: './app'});
  38. gulp.watch('./app/scss/*.scss', ['sass']);
  39. gulp.watch('./app/*.html', ['html-watch']);
  40. });
  41. /**
  42. * Simulate a slow task
  43. */
  44. function slowStream () {
  45. return through.obj(function (file, enc, cb) {
  46. this.push(file);
  47. setTimeout(cb, 2000);
  48. });
  49. }