Pau*_*oud 10 visual-studio-code
是否可以让 VS 代码在打开项目时运行多个命令并启动一个(或多个)应用程序?
我正在做的理想情况是:
目标是在 VS 代码中打开项目并开始工作,而不是运行几个设置步骤。
将此添加到项目文件夹中的 .vscode/tasks.json 中,以在 VS 代码中打开文件夹时运行脚本或执行命令:
{
"version": "2.0.0",
"tasks": [
{
"label": "Launch app", // Name of task
"type": "shell",
"command": "npm start", // Enter your command here
"group": "none",
"presentation": {
"reveal": "always",
"panel": "new"
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后你需要启用自动任务:
> Tasks: Manage Automatic Tasks in Folder下次您在该文件夹中打开 VS Code 时,您的任务将执行。
2019 年 8 月 12 日更新
@Andrew Wolfe 在评论中有一个很好的观点,询问工作区激活事件。当我在未来的项目中实现类似的配置时,我可能会朝这个方向发展。
原答案:
最终使用@HansPassant 的解决方案:https ://code.visualstudio.com/docs/editor/tasks#_custom-tasks
所以我的.vscode/tasks.json文件中有类似的东西:
{
"version": "2.0.0",
"tasks": [
{
"label": "Launch Ngrok",
"type": "shell",
"command": "ngrok http -subdomain=<SUBDOMAIN> <PORT>",
"windows": {
"command": "ngrok http -subdomain=<SUBDOMAIN> <PORT>"
},
"group": "none",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Launch App",
"type": "shell",
"command": "npm start",
"windows": {
"command": "npm start"
},
"group": "none",
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我还将我的项目保存为一个命名的工作区,以便我可以在循环浏览打开的项目时快速确定我正在查看哪个项目。
为每个项目添加了一个类似的tasks.json文件.vscode,然后每次我想要处理某事时,只需使用命令面板启动每个任务。
每个应用程序对需要同时运行的依赖项有不同的要求,一些通过本地节点启动,一些我在远程服务器上启动,一些我需要始终运行 TypeScript,然后 Rsync 到远程开发服务器(并绑定Rsync 任务到 cmd+option+s 以进行快速更新,更多信息在这里)。
这个解决方案使上述所有事情变得轻而易举,并使我不必记住每次运行每个项目的魔法咒语。
| 归档时间: |
|
| 查看次数: |
4117 次 |
| 最近记录: |