This commit is contained in:
tatianamac
2019-11-26 14:50:43 -08:00
parent 8a55660ed0
commit 6d5445ecc5
13894 changed files with 2233957 additions and 0 deletions

View File

@ -0,0 +1,2 @@
body {
background: white; }

View File

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Browsersync, Gulp, SASS + Slow tasks example</title>
<link rel='stylesheet' href='css/main.css'>
</head>
<body>
<h1>Browsersync, Gulp, SASS + Slow tasks example</h1>
</body>
</html>

View File

@ -0,0 +1,3 @@
body {
background: white;
}

View File

@ -0,0 +1,5 @@
This example highlights a common problem where you don't want to reload
the browser until a 2 or more slow-running tasks have completed. The solution
is to create the intermediate task that ensures `browserSync.reload` is not
called until both slow tasks are complete.

View File

@ -0,0 +1,57 @@
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var reload = browserSync.reload;
var through = require("through2");
/**
* A slow task
*/
gulp.task('slow1', function () {
return gulp.src('./app/*.html')
.pipe(slowStream());
});
/**
* Another Slow task
*/
gulp.task('slow2', function () {
return gulp.src('./app/*.html')
.pipe(slowStream());
});
/**
* Separate task for the reaction to a file change
*/
gulp.task('html-watch', ['slow1', 'slow2'], reload);
/**
* Sass task for live injecting into all browsers
*/
gulp.task('sass', function () {
return gulp.src('./app/scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./app/css'))
.pipe(reload({stream: true}));
});
/**
* Serve and watch the html files for changes
*/
gulp.task('default', function () {
browserSync({server: './app'});
gulp.watch('./app/scss/*.scss', ['sass']);
gulp.watch('./app/*.html', ['html-watch']);
});
/**
* Simulate a slow task
*/
function slowStream () {
return through.obj(function (file, enc, cb) {
this.push(file);
setTimeout(cb, 2000);
});
}

View File

@ -0,0 +1,17 @@
{
"name": "gulp.sass",
"version": "1.0.0",
"description": "Gulp, SASS + Slow running tasks",
"main": "gulpfile.js",
"scripts": {
"start": "gulp"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.2.0",
"gulp": "^3.8.11",
"gulp-sass": "^1.3.3",
"through2": "^0.6.3"
}
}

View File

@ -0,0 +1,97 @@
#Browsersync - Gulp, SASS + Slow running tasks
## Installation/Usage:
To try this example, follow these 4 simple steps.
**Step 1**: Clone this entire repo
```bash
$ git clone https://github.com/Browsersync/recipes.git bs-recipes
```
**Step 2**: Move into the directory containing this example
```bash
$ cd bs-recipes/recipes/gulp.task.sequence
```
**Step 3**: Install dependencies
```bash
$ npm install
```
**Step 4**: Run the example
```bash
$ npm start
```
### Additional Info:
This example highlights a common problem where you don't want to reload
the browser until a 2 or more slow-running tasks have completed. The solution
is to create the intermediate task that ensures `browserSync.reload` is not
called until both slow tasks are complete.
### Preview of `gulpfile.js`:
```js
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var reload = browserSync.reload;
var through = require("through2");
/**
* A slow task
*/
gulp.task('slow1', function () {
return gulp.src('./app/*.html')
.pipe(slowStream());
});
/**
* Another Slow task
*/
gulp.task('slow2', function () {
return gulp.src('./app/*.html')
.pipe(slowStream());
});
/**
* Separate task for the reaction to a file change
*/
gulp.task('html-watch', ['slow1', 'slow2'], reload);
/**
* Sass task for live injecting into all browsers
*/
gulp.task('sass', function () {
return gulp.src('./app/scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./app/css'))
.pipe(reload({stream: true}));
});
/**
* Serve and watch the html files for changes
*/
gulp.task('default', function () {
browserSync({server: './app'});
gulp.watch('./app/scss/*.scss', ['sass']);
gulp.watch('./app/*.html', ['html-watch']);
});
/**
* Simulate a slow task
*/
function slowStream () {
return through.obj(function (file, enc, cb) {
this.push(file);
setTimeout(cb, 2000);
});
}
```