Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I watch multiple TypeScript projects in VSCode?

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:

  1. creates 10 command line windows, so that the watch can be later closed
  2. runs invisibly, in which case the watch can only be killed from the task manager

... 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.

like image 788
John Weisz Avatar asked Mar 06 '17 20:03

John Weisz


People also ask

How do I open multiple projects in Visual Studio?

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.

How do I open multiple folders in VS Code?

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.


1 Answers

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"
      ]
    }
  ]
}
like image 106
Get Off My Lawn Avatar answered Oct 12 '22 00:10

Get Off My Lawn