【问题标题】:Angular 2 disable mirror of browsersyncAngular 2禁用浏览器同步镜像
【发布时间】:2017-04-05 21:22:06
【问题描述】:

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

另外,我用这个命令开始我的项目:

npm start

这是我的文件:

更新 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"
  }
}

谁能帮帮我?

【问题讨论】:

    标签: angular


    【解决方案1】:

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

    在您的代码库中搜索browserSync.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 中的“启动”命令,以使用新的配置文件运行 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.

    【讨论】:

    • 感谢您的回答@Adam 我在我的任何文件中都没有看到任何“开始”:(我将使用这些文件内容更新我的答案。
    • 我的错!我在 packages.json 上找到了这个:"start": "tsc && concurrently \"tsc -w\" \"lite-server\" "
    • 看看我的编辑,lite-server默认使用浏览器同步,你只需要覆盖配置。
    • 非常感谢我的朋友!我会审查这个,我会告诉你是否有效
    • 嗨,我的朋友,这就像一个魅力!非常感谢。我还有一个问题......也许你可以帮助我。我怎样才能把这个项目变成一个生产环境?我看到其他项目有一个“dist”文件夹...
    【解决方案2】:

    对我来说,我需要添加;

    {"ghostMode": false} 
    

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

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 2016-06-21
      • 2016-07-21
      • 2017-04-26
      • 2015-01-28
      • 1970-01-01
      • 2010-11-02
      • 2015-04-15
      相关资源
      最近更新 更多