Mayu
Mayu

Reputation: 25

How do I kill browserSync before creating it?

Before executing "var bs = browserSync.create();", I would like to kill browserSync if a browserSync process is running.

Is it correct that exit() method needs a browsersync instance? ( https://www.browsersync.io/docs/api#api-exit)

What is the best way ?

//A gulp script

var browserSync = require('browser-sync');

//Step 1 --- Kill browsersync

?

//Step2 --- Start browsersync

var bs = browserSync.create();

Upvotes: 0

Views: 1187

Answers (1)

xkeshav
xkeshav

Reputation: 54042

reference from the documentation

var bs = require("browser-sync").create();
console.log(bs.active); // will return true/false whether browserSync is running or not

if(bs.active) {
    bs.exit();
} else {
    bs.init(config, function (err, bs) {    
    // -> now true since BS is running now
    console.log(bs.active);
   });
}

Upvotes: 1

Related Questions