【问题标题】:Visual Studio Code - Debug Angular 2 against specific environmentVisual Studio Code - 针对特定环境调试 Angular 2
【发布时间】:2017-09-19 10:42:38
【问题描述】:

我是 Angular 的新手,我正在尝试在 Visual Studio 代码中调试代码。对于调试,我使用 Chrome 的扩展调试器,配置如下:

**launch.json**
{
    "version": "0.2.0",
    "configurations": [       
      {
        "name": "ng serve",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:4200/#",
        "webRoot": "${workspaceRoot}"                                    
      },
      {
        "name": "ng test",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:9876/debug.html",
        "webRoot": "${workspaceRoot}"
      },
      {
        "name": "ng e2e",
        "type": "node",
        "request": "launch",
        "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
        "protocol": "inspector",
        "args": ["${workspaceRoot}/protractor.conf.js"]
      }      
    ]
  }

它工作正常。但是我有环境问题。我有 3 种不同的环境。在 environemnt.ts 我有到 localhost 的路由,接下来的两个是服务器上的 api,例如 environemnt.tst1.ts 和 environemnt.tst2.ts。

如果我想通过 Angular cli 执行某些环境,没关系。我写了 ng serve --env=ts 并针对环境 ts1 工作。但是如果我想调试。我必须写 npm start (这是调试模式的条件),它会生成以下代码:

npm start

> web-client@0.0.0 start C:\GitProjects\web-client
> ng serve --host 0.0.0.0 --port 4200

但它适用于基本环境。ts

我的问题是,我该如何选择另一个环境。我正在尝试 f.e.有些人在配置文件中添加参数env,值为ts1,但它写的是mi,不允许使用Property env。

你有解决这个问题的经验吗?

谢谢。

【问题讨论】:

    标签: angular debugging visual-studio-code


    【解决方案1】:

    问题解决了,我想,所以我必须在配置调试器中设置它,但我在 package.json 中设置它。添加参数 env=tst1。

    {
      "name": "web-client",
      "version": "0.0.0",
      "license": "MIT",
      "scripts": {
        "ng": "ng",
        "start": "ng serve --host 0.0.0.0 --port 4200 --env=tst1",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e"
      },
    ....
    

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      • 2021-11-26
      • 2021-10-15
      相关资源
      最近更新 更多