0

在执行“var bs = browserSync.create();”之前,如果 browserSync 进程正在运行,我想终止 browserSync。

exit() 方法需要 browsersync 实例是否正确?( https://www.browsersync.io/docs/api#api-exit )

什么是最好的方法 ?

//一个gulp脚本

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

//步骤 1 --- 杀死 browsersync

?

//Step2 --- 开始浏览器同步

var bs = browserSync.create();
4

1 回答 1

1

来自文档的参考

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);
   });
}
于 2016-07-26T03:59:44.643 回答