Skip to content

Instantly share code, notes, and snippets.

@clowestab
Created August 3, 2017 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clowestab/df78ee6ded2dc90f8ab5e0d03d743761 to your computer and use it in GitHub Desktop.
Save clowestab/df78ee6ded2dc90f8ab5e0d03d743761 to your computer and use it in GitHub Desktop.
//Watches our .jsx files and our .js. If any change, it calls the build task.
const gulp = require('gulp');
const runSequence = require('run-sequence');
const gutil = require('gulp-util');
//Boolean to hold state of watch JSX watch task
let taskOngoing = false;
//This task simply sets the taskOngoing boolean to false
gulp.task('jsxdone', function(callback) {
gutil.log('JSX done executed');
taskOngoing = false;
callback();
});
//Does the 'watching'
gulp.task('watch', function() {
//Watches .jsx files
gulp.watch('../../public/assets/jsx/**/*.jsx', function(){
//Indicate that we are running the JSX watch
taskOngoing = true;
gutil.log('Running JSX watch');
//Once the jsx task is executed we will execute jsxdone
runSequence('jsx', 'jsxdone', 'browserify');
//THIS line is discussed below
gutil.log('Run sequence is NOT finished');
});
//Watches .js files
gulp.watch('../../public/assets/js/**/*.js', function(){
if (!taskOngoing) {
gutil.log('Running Javascript watch');
runSequence('browserify');
} else {
//If our jsx - browserify watch task is executing then we will not allow this watch to execute
gutil.log('SKIPPING Javascript watch. JSX task ongoing ' + (taskOngoing ? "true" : "false"));
}
});
//Watches .css file for changes
gulp.watch('../../public/assets/css/simple.css', ['cssconcat']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment