You can use Yargs to send parameters and enable or disable the watch task.
Remember this command line to install the necessary components:
npm i --save gulp browser-sync yargs runSequence
In the gulpfile.js file:
browserSync.init({ port: 80, notify: false, cors: true, browser: 'chrome', open: 'local' }); gulp.task('watch', ['browserSync'], function (){ gulp.watch('dev/*.html', browserSync.reload); gulp.watch('dev/**/*.js', browserSync.reload); gulp.watch('dev/**/*.css', browserSync.reload); }); gulp.task('default', function(callback) { var sequence = ['browserSync']; if (args.sync){ sequence.push('watch') } runSequence(sequence,callback); });
These if (args.sync) lines use truthfulness / falsehood, looking for sync values and turning on / off the watch task.
BrowserSync with a clock:
gulp --sync true
BrowserSync without hours:
gulp or gulp --sync false
source share