如何实现`au run --watch`任务+调试

时间:2017-04-12 20:42:15

标签: visual-studio-code aurelia

我正在尝试在VS Code中为基于Aurelia CLI的应用程序实施“F5”调试。 Aurelia CLI基于Gulp任务构建。我想设置一个运行au run --watch的任务,并在按“F5”进行调试时启动此任务(“启动Chrome”选项)。

au run --watch命令创建基本任务非常简单。

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "0.1.0",
  "command": "au",
  "isShellCommand": true,
  "tasks": [
    {
      "taskName": "watch",
      "suppressTaskName": true,
      "args": [
        "run",
        "--watch"
      ],
      "isBuildCommand": false,
      "isBackground": true
      }
  ]
}

然后,当我按F5将其添加到“启动针对localhost的Chrome”调试配置时,我可以启动此任务:

    {
        "type": "chrome",
        "request": "launch",
        "name": "Launch Chrome against localhost",
        "url": "http://localhost:9000",
        "webRoot": "${workspaceRoot}",
        "preLaunchTask": "watch"
    }

我看到的问题是,由于此任务是一项无法完成的“监视”任务,因此代码永远不会启动Chrome标签页或启动调试会话。

我尝试在我的任务配置中添加了“problemMatcher”,但坦率地说,此功能的文档有点稀疏。我得到的错误输出似乎与JSON模式所说的不一致。希望有人可以帮助我。这是我当前的非工作任务配置。当我说非工作时,我的意思是任务成功运行,但VS Code没有注意到任务的观看部分已经开始。

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "0.1.0",
  "command": "au",
  "isShellCommand": true,
  "tasks": [
    {
      "taskName": "watch",
      "suppressTaskName": true,
      "args": [
        "run",
        "--watch"
      ],
      "isBuildCommand": false,
      "isBackground": true,
      "problemMatcher": {
        "owner": "au",
        "severity": "info",
        "fileLocation": [
          "relative",
          "${workspaceRoot}"
        ],
        "pattern": {
          "regexp": "^BrowserSync Available At: http://localhost:3001$",
          "file": 1
        },
        "watching": {
          "activeOnStart": true,
          "beginsPattern": "^File Changed: (.*)", 
          "endsPattern": "^Finished 'reload'"
        }
      }
    }
  ]
}

作为参考,当我运行此任务时,这是命令的输出:

Starting 'readProjectConfiguration'...
Finished 'readProjectConfiguration'
Starting 'processMarkup'...
Starting 'processCSS'...
Starting 'copyFiles'...
Starting 'configureEnvironment'...
Finished 'copyFiles'
Finished 'processCSS'
Finished 'processMarkup'
Finished 'configureEnvironment'
Starting 'buildJavaScript'...
Finished 'buildJavaScript'
Starting 'writeBundles'...
Tracing app...
Tracing environment...
Tracing main...
Tracing resources/index...
Tracing app...
Tracing aurelia-binding...
Tracing aurelia-bootstrapper...
Tracing aurelia-dependency-injection...
Tracing aurelia-event-aggregator...
Tracing aurelia-framework...
Tracing aurelia-history...
Tracing aurelia-history-browser...
Tracing aurelia-loader-default...
Tracing aurelia-logging-console...
Tracing aurelia-pal-browser...
Tracing aurelia-route-recognizer...
Tracing aurelia-router...
Tracing aurelia-templating-binding...
Tracing text...
Tracing aurelia-templating-resources...
Tracing aurelia-templating-router...
Tracing aurelia-testing...
Writing app-bundle.js...
Writing vendor-bundle.js...
Finished 'writeBundles'
Application Available At: http://localhost:9000
BrowserSync Available At: http://localhost:3001

当我编辑并保存文件时,会在控制台输出中添加以下内容:

File Changed: src\app.js
Starting 'readProjectConfiguration'...
Finished 'readProjectConfiguration'
Starting 'processMarkup'...
Starting 'processCSS'...
Starting 'copyFiles'...
Starting 'configureEnvironment'...
Finished 'copyFiles'
Finished 'processCSS'
Finished 'processMarkup'
Finished 'configureEnvironment'
Starting 'buildJavaScript'...
Finished 'buildJavaScript'
Starting 'writeBundles'...
Tracing app...
Writing app-bundle.js...
Finished 'writeBundles'
Starting 'reload'...
Finished 'reload'

1 个答案:

答案 0 :(得分:2)

我们知道这一点,并且两个相应的GitHub问题是:

我们计划以两种方式改善这一点:

  • 调试将在超时后询问是否要启动调试,即使启动前任务尚未完成
  • 任务框架将允许在任务本身上指定监视属性,而无需问题匹配器。

问题6209包含了如何解决此问题的步骤,并且您正走在正确的道路上:-)。应该有所不同的事情:

由于您不想匹配任何问题,请使用与任何内容都不匹配的正则表达式。类似的东西:

"pattern": {
    "regexp": "__________"
}

更大的问题是,在第一次运行时,活动结束的信号不同,然后对文件更改做出反应。因此,endsPattern必须与BrowserSync Available At: http://localhost:3001Finished 'reload'匹配。所以像/(?:BrowserSync Available At:)|(?:Finished 'reload')/这样的正则表达式 beginPattern和"activeOnStart": true是正确的。

如果你还没有上班,请在#6209中给我打电话。