用于ng build的VSCode tasks.json --watch

时间:2018-02-18 19:21:18

标签: angular visual-studio-code

我没有找到有效的角色cli“ng build --watch”commapnd的Visual Studio Code tasks.json定义。有人可以帮助一个经过良好测试的定义吗?

重现,尝试出错,然后修复它。错误将保留在“问题选项卡”

还需要“ng lint”的任务定义。

这就是我所拥有的,而且效果不佳。

var currentTemp= "cel";
  $("#tempUnit").click(function(){

  alert("Temperature Changed to Fahrenheit.");
//   var currentTemp= cel;
    if (currentTemp=== "cel") {
    currentTemp = "faren"; 
      var farCalc=  (data.main.temp * 1.8) + 32;

   $('#temp').html("Temperature:" + Math.round(farCalc) +"");
     $('#tempUnit').html("&#8457");
   }
    if (currentTemp=== "faren"){

  alert("Temperature Changed to Celsius");
   $('#temp').html("Temperature:" + data.main.temp +"");
     $('#tempUnit').html("&#8451");  
      } 

}

2 个答案:

答案 0 :(得分:0)

这是我对ng build的task.json定义(对Typescript扩展名definition的一些修改),我想您也可以将其用于ng build --watch:

{
    "label": "show all TS errors: ng build",
    "type": "npm",
    "script": "build",
    "problemMatcher": {
        "owner": "typescript",
        "source": "ts",
        "applyTo": "closedDocuments",
        "pattern": {
            "regexp": "^ERROR in ([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "code": 5,
            "message": 6
        },
        "fileLocation": "relative"
    }
}

对于ng lint:

{
    "label": "show all TSLint errors: ng lint",
    "type": "npm",
    "script": "lint",
    "problemMatcher": "$tslint5"
},

package.json:

"scripts": {
    "ng": "ng",
    "build": "ng build",
    "lint": "ng lint",
},

$tslint5 problemMatcher包含在扩展名TypeScript TSLint PluginTSLint中。我建议使用第一个扩展程序,因为它是第二个扩展程序的改进版本,并支持 语言服务插件。您可以在其页面上找到安装说明。

答案 1 :(得分:0)

使用此手表:

{
          "label": "ng serve",
          "type": "npm",
          "script": "start",
          "group": "build",
          "isBackground": true,
          "presentation": {
            "focus": true,
            "panel": "dedicated"
          },
          "problemMatcher": {
            "owner": "typescript",
            "source": "ts",
            "applyTo": "allDocuments",
            "fileLocation": [
              "relative",
              "${cwd}"
            ],
            "pattern":   {
              "regexp": "^\\s*(?:ERROR in )?([^\\s].*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+TS(\\d+)\\s*:\\s*(.*)$",
              "file": 1,
              "line": 2,
              "column": 3,
              "severity": 4,
              "code": 5,
              "message": 6
            },
            "background": {
              "activeOnStart": true,
              "beginsPattern": {
                "regexp": "Compiling\\.\\.\\.$"
              },
              "endsPattern": {
                "regexp": "Compiled successfully\\.$|Failed to compile"
              }
            }
          }
      }