You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 2.0 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #Browsersync - Gulp, SASS + Slow running tasks
  2. ## Installation/Usage:
  3. To try this example, follow these 4 simple steps.
  4. **Step 1**: Clone this entire repo
  5. ```bash
  6. $ git clone https://github.com/Browsersync/recipes.git bs-recipes
  7. ```
  8. **Step 2**: Move into the directory containing this example
  9. ```bash
  10. $ cd bs-recipes/recipes/gulp.task.sequence
  11. ```
  12. **Step 3**: Install dependencies
  13. ```bash
  14. $ npm install
  15. ```
  16. **Step 4**: Run the example
  17. ```bash
  18. $ npm start
  19. ```
  20. ### Additional Info:
  21. This example highlights a common problem where you don't want to reload
  22. the browser until a 2 or more slow-running tasks have completed. The solution
  23. is to create the intermediate task that ensures `browserSync.reload` is not
  24. called until both slow tasks are complete.
  25. ### Preview of `gulpfile.js`:
  26. ```js
  27. var gulp = require('gulp');
  28. var browserSync = require('browser-sync');
  29. var sass = require('gulp-sass');
  30. var reload = browserSync.reload;
  31. var through = require("through2");
  32. /**
  33. * A slow task
  34. */
  35. gulp.task('slow1', function () {
  36. return gulp.src('./app/*.html')
  37. .pipe(slowStream());
  38. });
  39. /**
  40. * Another Slow task
  41. */
  42. gulp.task('slow2', function () {
  43. return gulp.src('./app/*.html')
  44. .pipe(slowStream());
  45. });
  46. /**
  47. * Separate task for the reaction to a file change
  48. */
  49. gulp.task('html-watch', ['slow1', 'slow2'], reload);
  50. /**
  51. * Sass task for live injecting into all browsers
  52. */
  53. gulp.task('sass', function () {
  54. return gulp.src('./app/scss/*.scss')
  55. .pipe(sass())
  56. .pipe(gulp.dest('./app/css'))
  57. .pipe(reload({stream: true}));
  58. });
  59. /**
  60. * Serve and watch the html files for changes
  61. */
  62. gulp.task('default', function () {
  63. browserSync({server: './app'});
  64. gulp.watch('./app/scss/*.scss', ['sass']);
  65. gulp.watch('./app/*.html', ['html-watch']);
  66. });
  67. /**
  68. * Simulate a slow task
  69. */
  70. function slowStream () {
  71. return through.obj(function (file, enc, cb) {
  72. this.push(file);
  73. setTimeout(cb, 2000);
  74. });
  75. }
  76. ```