How to temporarily disable browsersync?
Asked Answered
H

2

6

How can I temporarily disable browsersync, so that it doesn't inject/modify HTML pages? (For testing and debugging.)

Haunt answered 20/12, 2014 at 9:48 Comment(0)
H
10

There doesn't seem to be a configuration option to do just this, but one hacky workaround is to use snippetOptions to specify a string that will will never be found in the HTML:

snippetOptions: {
  rule: {
    match: /qqqqqqqqq/
  }
}

If this string cannot be found in the HTML, the snippet will never be injected, and browsersync will be inert.

Haunt answered 20/12, 2014 at 9:48 Comment(0)
F
0

You can use Yargs to send parameters and enable or disable 'watch' task.

Remember this command line to install required components:
npm i --save gulp browser-sync yargs runSequence

On 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);
});

This if (args.sync) lines use truthy/falsy searching for sync values and enable/disable 'watch' task.

BrowserSync with watch:
gulp --sync true

BrowserSync without watch:
gulp or gulp --sync false

Fisken answered 23/6, 2017 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.