I'm browsersync in gulp, with the below setup. The issue is that when code changes, browsersync recognizes this and refreshes the page. However, it doesn't wait for the script file to be in the gulp.dest so generally it refreshes automatically and the script file cannot be found, then refreshing again, it's there.
Is there a way to ensure it will wait for the task to fully complete?
var browserSync = require('browser-sync').create(); gulp.task('cleanScripts', function () { return gulp.src('./assets/js', {read: false}) .pipe(clean()); }); gulp.task('scripts', ['cleanScripts'], function() { return browserify('./client/js/main.js') .bundle() .on('error', function (e) { gutil.log(e); }) .pipe(source('main-' + packageJson.version + '.js')) .pipe(buffer()) .pipe(uglify()) .pipe(gulp.dest('./assets/js')); }); //Watch our changes gulp.task('watch', function () { browserSync.init({ proxy: "localhost:3000" }); gulp.watch(['./client/js/**/*.js', ['scripts']).on('change', browserSync.reload); });