【问题标题】:How do I kill browserSync before creating it?如何在创建 browserSync 之前杀死它?
【发布时间】:2016-07-06 18:35:37
【问题描述】:

在执行“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();

【问题讨论】:

    标签: browser-sync gulp-browser-sync


    【解决方案1】:

    来自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);
       });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多