很多个package都需要构建到每个项目的 lib 下,可以用 vscode 的 tasks.json 任务去实现。
具体 tasks.json 的详情请看官网 : https://code.visualstudio.com/docs/editor/tasks
项目结构如下 :
packages/
+ apis
+ core
+ utils
pnpm-workspace.yaml
直接新建一个 .vscode 文件夹,并且新建 tasks.json 文件
{
"version": "2.0.0",
"tasks": [
{
"label": "watch-apis",
"args": ["-p", "packages/apis/tsconfig.json", "--watch"],
"type": "shell",
"command": "tsc",
"isBackground": true,
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "silent",
"panel": "new"
},
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "watch-core",
"args": ["-p", "packages/core/tsconfig.json", "--watch"],
"type": "shell",
"command": "tsc",
"isBackground": true,
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "silent",
"panel": "new"
},
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "watch-utils",
"args": ["-p", "packages/utils/tsconfig.json", "--watch"],
"type": "shell",
"command": "tsc",
"isBackground": true,
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "silent",
"panel": "new"
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
最后重启 vscode 后,全部任务会直接运行,并且监听构建每个子目录 ts 文件。