我可以在打开文件夹时自动启动任务吗?
Can I automatically start a task when a folder is opened?
VS 代码是否支持在启动时启动 gulp-watch 任务?我想在打开编辑器时启动观察器。
不,对不起。这是一个很好的建议(能够 运行 启动时的任务),你能在 GitHub 的 microsoft/vscode 回购中提出问题吗? (抱歉,我还不能 post 超过 2 个链接)?
同时,这里有几个选项:
您可以将特定任务指定为构建任务,然后在打开文件夹时按 CMD+SHIFT+B
以启动任务。看这里:https://code.visualstudio.com/docs/editor/tasks#_mapping-gulp-grunt-and-jake-output-to-problem-matchers
您可以编写一个在启动时激活的扩展程序,然后 运行s gulp 使用任务名称。请在此处查看扩展激活选项:https://code.visualstudio.com/docs/extensionAPI/activation-events#_activationevents。
我创建了一个可以做到这一点的扩展。
是"Blade Runner"。试试这个! Blade Runner on Visual Studio Code Market Place
这是一个旧线程,但问题仍然是最新的。 Blade Runner 不适合我的需求,其他任何扩展也不适合。
我创建了一个扩展 AutoLaunch,它可以 运行 来自 tasks.json 的特定任务或来自 launch.json 的特定调试配置。
此功能是在 v1.30 中添加的:Release notes: run task on folder open
Run on folder open
If you have a task that you always run when you open a folder, you can
configure it to run automatically when that folder is opened by
configuring its "runOn
" property. We found this useful for making sure
no one breaks our new strict null checks in the VS Code repository. By
adding "runOn": "folderOpen"
, everyone who allows tasks to be run
automatically will get markers when they violate the strict null
check:
示例:
{
"type": "npm",
"script": "strict-null-check-watch",
"label": "TS - Strict Null Checks",
"isBackground": true,
"problemMatcher": {
"base": "$tsc-watch",
"owner": "typescript-strict-null",
"applyTo": "allDocuments"
},
"runOptions": {
"runOn": "folderOpen"
}
}
示例 2:
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [
"copy3",
"--file",
"${fileBasename}"
],
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
}
},
正如 Mark 所建议的,您可以使用 "runOn": "folderOpen"
,但我认为 运行 一项 Gulp 任务并不那么简单。我建议尝试按照以下方式进行操作。
{
"label": "Watch",
"type": "shell",
"command": "gulp watch",
"runOptions": {
"runOn": "folderOpen"
}
)
VS 代码是否支持在启动时启动 gulp-watch 任务?我想在打开编辑器时启动观察器。
不,对不起。这是一个很好的建议(能够 运行 启动时的任务),你能在 GitHub 的 microsoft/vscode 回购中提出问题吗? (抱歉,我还不能 post 超过 2 个链接)?
同时,这里有几个选项:
您可以将特定任务指定为构建任务,然后在打开文件夹时按
CMD+SHIFT+B
以启动任务。看这里:https://code.visualstudio.com/docs/editor/tasks#_mapping-gulp-grunt-and-jake-output-to-problem-matchers您可以编写一个在启动时激活的扩展程序,然后 运行s gulp 使用任务名称。请在此处查看扩展激活选项:https://code.visualstudio.com/docs/extensionAPI/activation-events#_activationevents。
我创建了一个可以做到这一点的扩展。 是"Blade Runner"。试试这个! Blade Runner on Visual Studio Code Market Place
这是一个旧线程,但问题仍然是最新的。 Blade Runner 不适合我的需求,其他任何扩展也不适合。
我创建了一个扩展 AutoLaunch,它可以 运行 来自 tasks.json 的特定任务或来自 launch.json 的特定调试配置。
此功能是在 v1.30 中添加的:Release notes: run task on folder open
Run on folder open
If you have a task that you always run when you open a folder, you can configure it to run automatically when that folder is opened by configuring its "
runOn
" property. We found this useful for making sure no one breaks our new strict null checks in the VS Code repository. By adding"runOn": "folderOpen"
, everyone who allows tasks to be run automatically will get markers when they violate the strict null check:
示例:
{
"type": "npm",
"script": "strict-null-check-watch",
"label": "TS - Strict Null Checks",
"isBackground": true,
"problemMatcher": {
"base": "$tsc-watch",
"owner": "typescript-strict-null",
"applyTo": "allDocuments"
},
"runOptions": {
"runOn": "folderOpen"
}
}
示例 2:
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [
"copy3",
"--file",
"${fileBasename}"
],
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
}
},
正如 Mark 所建议的,您可以使用 "runOn": "folderOpen"
,但我认为 运行 一项 Gulp 任务并不那么简单。我建议尝试按照以下方式进行操作。
{
"label": "Watch",
"type": "shell",
"command": "gulp watch",
"runOptions": {
"runOn": "folderOpen"
}
)