gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:32:24 25 4
gpt4 key购买 nike

我正在尝试在 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 时启动此任务,方法是将其添加到“针对本地主机启动 Chrome”调试配置中:
    {
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:9000",
"webRoot": "${workspaceRoot}",
"preLaunchTask": "watch"
}

我看到的问题是,由于此任务是未完成的“监视”任务,因此代码永远不会启动 Chrome 选项卡或启动调试 session 。

我试过在我的任务配置中添加一个“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'

最佳答案

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

  • https://github.com/Microsoft/vscode/issues/6209
  • https://github.com/Microsoft/vscode/issues/24589

  • 我们计划通过两种方式改进这一点:
  • 即使预启动任务尚未完成,调试也会在超时后询问是否要开始调试
  • 任务框架将允许在不需要问题匹配器的情况下指定任务本身的观察属性。

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

    由于您不想匹配任何问题,因此请使用不匹配任何内容的正则表达式。就像是:
    "pattern": {
    "regexp": "__________"
    }

    更大的问题是,在第一次运行时,事件结束的信号与响应文件更改时不同。所以endsPattern 必须同时匹配 BrowserSync Available At: http://localhost:3001Finished 'reload' .所以正则表达式类似于 /(?:BrowserSync Available At:)|(?:Finished 'reload')/开始模式和 "activeOnStart": true是正确的。

    如果您仍然无法使用它,请在 #6209 中 ping 我。

    关于visual-studio-code - 如何实现 `au run --watch`任务+调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43379296/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com