Angular 2禁用browsersync的镜像

时间:2017-04-05 21:22:06

标签: angular

我为Angular 2项目使用了一个模板。这个项目不使用gulp或webpack。我在Angular 2上真的很新。如果我在不同的计算机上打开多个Web浏览器,它会反映我在特定计算机上的所有操作。我怎么能禁用它?我没有看到我的端口的任何配置文件(它是3000但我不知道如何更改它)或浏览器同步的任何配置文件...我很困惑!

另外,我使用此命令启动项目:

npm start

这是我的档案:

enter image description here

更新1

systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'angular2-jwt': 'npm:angular2-jwt/angular2-jwt.js',
      'ng2-toasty': 'node_modules/ng2-toasty/bundles/index.umd.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      "angular2-jwt": {
                "defaultExtension": "js"
            },
    }
  });
})(this);


package.json

{
  "name": "cayena-oak",
  "private": true,
  "version": "1.1.1",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "engines": {
    "node": "5.9.1"
  },
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/creativetimofficial/light-bootstrap-dashboard-angular.git"
  },
  "bugs": {
    "url": "https://github.com/creativetimofficial/light-bootstrap-dashboard-angular/issues"
  },
  "dependencies": {
    "@angular/common": "~2.2.2",
    "@angular/compiler": "~2.2.2",
    "@angular/core": "~2.2.2",
    "@angular/forms": "~2.2.2",
    "@angular/http": "~2.2.2",
    "@angular/platform-browser": "~2.2.2",
    "@angular/platform-browser-dynamic": "~2.2.2",
    "@angular/router": "~3.2.2",
    "@angular/upgrade": "~2.2.2",
    "@types/core-js": "0.9.35",
    "@types/node": "^6.0.45",
    "angular-in-memory-web-api": "~0.1.13",
    "angular2-chartist": "~0.10.1",
    "angular2-google-maps": "~0.16.0",
    "angular2-jwt": "^0.1.28",
    "chartist": "~0.9.8",
    "compression": "^1.6.2",
    "core-js": "2.4.1",
    "jquery": "~3.1.1",
    "ng2-bootstrap": "~1.1.16",
    "ng2-toasty": "^2.5.0",
    "reflect-metadata": "~0.1.8",
    "rxjs": "5.0.0-rc.5",
    "systemjs": "~0.19.41",
    "systemjs-builder": "^0.15.17",
    "typescript": "^2.0.3",
    "yargs": "^4.7.1",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@types/chartist": "~0.9.33",
    "@types/core-js": "~0.9.34",
    "@types/jquery": "~2.0.34",
    "@types/node": "~6.0.45",
    "concurrently": "^3.0.0",
    "lite-server": "~2.2.2",
    "typescript": "~2.0.3",
    "ejs": ">= 0.0.1",
    "express": "~4.9.8",
    "nodemon": "^1.11.0",
    "systemjs": "0.19.39"
  }
}

任何人都可以帮助我?

2 个答案:

答案 0 :(得分:3)

您需要找到您的browserSync实例的初始化位置,并将ghostMode更改为false。

在代码库中搜索browserSync.init,看看是否可以看到初始化的位置,然后可以修改init选项。我认为它会在systemjs.config.js中,但如果没有看到你的代码就很难说。

如果找不到它,请尝试跟踪包配置,从packages.json开始,找到启动命令,查看运行的内容,加载的文件以及跟踪,直到找到browserSync初始化。

参考:How to disable cross-device action mirroring functionality of BrowserSync? (GhostMode)

修改

关于您的评论,看起来您正在使用lite-server来运行您的应用。要覆盖默认的browsersync配置,您需要创建一个名为my-bs-config.json的文件来覆盖默认配置,并将其放入您的文件中:

{
  "ghost": false
}

然后还在package.json中更改你的“start”命令,用新配置文件运行lite-server,这些内容如下:

lite-server -c my-bs-config.json

所以你的新命令是:

"start": "tsc && concurrently \"tsc -w\" \"lite-server -c my-bs-config.json\" "

我没有对它进行测试以确保其正常工作,因此您可能需要稍微调整该命令才能使其正常工作。如果您遇到问题,请留言,我会尝试为您修复命令。

This is based off of the lite-server documentation, which can be found here.

答案 1 :(得分:0)

对我来说,我需要添加;

{"ghostMode": false} 

在新创建的bs-config.json上使其工作。