command shift p
搜索 Tasks,或者点菜单栏的 Terminal 选择 configure tasks,你会看到一个新的列表,从中选择一个 script 作为 task 执行的任务。
然后 vs code 会自动地在项目新建一个 ./vscode/tasks.json 文件,这里记载了 tasks 的配置信息。例如:
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "develop",
"problemMatcher": [],
"label": "npm: develop",
"detail": "gatsby develop",
"group": {
"kind": "build",
"isDefault": true
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
上面增加的 "runOn": "folderOpen"
规定当项目文件夹打开时自动执行这个 task。
如果不设置为自动执行,可以用快捷键 command shift b
快速执行,之所以是 b 应该是因为 "kind": "build"
,也可以通过 Terminal 执行。