javascript – 如何禁用浏览器同步的跨设备动作镜像功能? (GhostMode) - 代码日志

javascript – 如何禁用浏览器同步的跨设备动作镜像功能? (GhostMode)

我们的团队使用gornp角度发生器与yeoman来支架我们的网络应用程序。它使用browsersync来处理我们想要的实时重新加载。然而,我们刚刚部署到我们的开发服务器,现在两个开发人员同时使用gulp服务命令,它们都显示在同一个窗口中(即一个开发人员在一个窗口中显示,它显示在另一个开发者的窗口中)。我相信这是由于BrowserSync的跨设备测试功能,但是我对如何禁用此功能感到失望。如果有人知道如何做到这一点(最好没有禁用我们的实时重新加载功能)请让我知道!

以下是gulp文件夹中的server.js文件的代码,它与gulp-angular generator一起提供,所以希望这将有助于一些人。

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');

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

var util = require('util');

var proxyMiddleware = require('http-proxy-middleware');

function browserSyncInit(baseDir, browser) {
  browser = browser === undefined ? 'default' : browser;

  var routes = null;
  if(baseDir === conf.paths.src || (util.isArray(baseDir) && baseDir.indexOf(conf.paths.src) !== -1)) {
    routes = {
      '/bower_components': 'bower_components'
    };
  }

  var server = {
    baseDir: baseDir,
    routes: routes
  };

  /*
   * You can add a proxy to your backend by uncommenting the line bellow.
   * You just have to configure a context which will we redirected and the target url.
   * Example: $http.get('/users') requests will be automatically proxified.
   *
   * For more details and option, https://github.com/chimurai/http-proxy-middleware/blob/v0.0.5/README.md
   */
  // server.middleware = proxyMiddleware('/users', {target: 'http://jsonplaceholder.typicode.com', proxyHost: 'jsonplaceholder.typicode.com'});

  browserSync.instance = browserSync.init({
    startPath: '/',
    server: server,
    browser: browser
  });
}

browserSync.use(browserSyncSpa({
  selector: '[ng-app]'// Only needed for angular apps
}));

gulp.task('serve', ['watch'], function () {
  browserSyncInit([path.join(conf.paths.tmp, '/serve'), conf.paths.src]);
});

gulp.task('serve:dist', ['build'], function () {
  browserSyncInit(conf.paths.dist);
});

gulp.task('serve:e2e', ['inject'], function () {
  browserSyncInit([conf.paths.tmp + '/serve', conf.paths.src], []);
});

gulp.task('serve:e2e-dist', ['build'], function () {
  browserSyncInit(conf.paths.dist, []);
});
面对同样的问题,您可以在初始化选项中简单地将ghost模式设置为false。

     browserSync.instance = browserSync.init({
      startPath: '/',
      ghostMode: false,
      server: server,
      browser: browser
     });

不需要在default.config.js中更改:)

http://stackoverflow.com/questions/32510840/how-to-disable-cross-device-action-mirroring-functionality-of-browsersync-ghos

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:javascript – 如何禁用浏览器同步的跨设备动作镜像功能? (GhostMode)