Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have npm watch files in background to enable integration with Visual Studio Task Runner

I am trying to have npm watch for file changes in my client side code. I can have it work from the command line ok but I'd really like it to work from Visual Studio task runner.

my package.json looks something like this:

...
"watch": {
  "compile": {
  "patterns": [
      "wwwroot"
    ],
    "extensions": "ts"
  }
},
"scripts": {
  "prebuild": "copyfiles -f ./node_modules/d3/build/*.js ./wwwroot/lib/d3",
  "compile": "tsc && browserify ./wwwroot/app/app.js -o ./wwwroot/bundle.js",
  "build": "npm run compile",
  "watch": "npm-watch"
},
...

So running npm run build then npm run watch from the command line has everything running as expected.

When I use the Task Runner however to bind my watch script to the After Build event like this:

task runner screengrab

it never 'exits' and, as such, the build never completes* and Visual Studio waits for me to kill the task before the application runs. Is there a way to have the script run in the background or some kind of 'detached' mode to enable Visual Studio to complete the build and run the application?

I tried using different watch tools but can't find any such option in any of them.

*Actually, I guess the build itself probably DOES complete but VisualStudio never runs the app and just hangs waiting on the script exiting.

like image 314
Stewart_R Avatar asked Oct 29 '22 13:10

Stewart_R


1 Answers

Change the watch Bindings to Project Open. Then it will start watching after the project is opened.

like image 178
Rakesh Androtula Avatar answered Nov 16 '22 15:11

Rakesh Androtula