I have 10 TypeScript project folders next to each other, each containing a tsconfig.json
in its root. For various reasons, the projects need to be compiled separately. To automatically build a given project when its source changes, I'm running the following from a Windows batch file, for each project:
tsc -w
From the batch file, this is done by using start
, so that the different tsc
commands can run in parallel:
start tsc -w -p ./Project1
start tsc -w -p ./Project2
...
Now the problem is that this, depending on additional options, either:
... neither of which is desirable. So, what would be the "correct" way to watch multiple TypeScript projects in Visual Studio Code?
Edit
I was wrong about this part:
runs invisibly, in which case the watch can only be killed from the task manager
If the task is started using
start /B tsc -w -p ./Project1
... then closing the command prompt from which it was started will also close the "invisible" task, at least on Windows 10. I verified this from the Task Manager.
To open a second instance of the integrated development environment (IDE), right-click on the Visual Studio icon in your dock or Applications folder, and select New Instance.
You can simply do File>New Window and open the other project in the new window. Because after you close VSCODE and launch it again it opens only one of these two windows. But with workspace you keep both.
You can do this with a tasks file, but remember to use "version": "2.0.0"
as this doesn't work with older versions. Once you have created that file .vscode/tasks.json
put this in it and modify it to your needs. Once ready to run the task just run the main Build
task and it should startup your other tsc
tasks.
{
"version": "2.0.0",
"command": "tsc",
"problemMatcher":"$tsc-watch",
"showOutput": "always",
"echoCommand": true,
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"dependsOn": [
"Build A",
"Build B",
"Build C"
]
},
{
"taskName": "Build A",
"args": [
"-w", "-p", "./src/project-a"
]
},
{
"taskName": "Build B",
"args": [
"-w", "-p", "./src/project-b"
]
},
{
"taskName": "Build C",
"args": [
"-w", "-p", "./src/project-c"
]
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With