在后台使用 npm watch 文件以启用与 Visual Studio Task Runner 的集成 [英] Have npm watch files in background to enable integration with Visual Studio Task Runner

查看:22
本文介绍了在后台使用 npm watch 文件以启用与 Visual Studio Task Runner 的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 npm 监视客户端代码中的文件更改.我可以从命令行运行它,但我真的很喜欢它在 Visual Studio 任务运行器中运行.

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.

我的 package.json 看起来像这样:

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"
},
...

所以从命令行运行 npm run build 然后 npm run watch 一切都按预期运行.

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

然而,当我使用 Task Runner 将我的监视脚本绑定到 After Build 事件时,如下所示:

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

它永远不会退出",因此,构建永远不会完成*并且 Visual Studio 在应用程序运行之前等待我终止任务.有没有办法让脚本在后台或某种分离"模式下运行,让 Visual Studio 完成构建并运行应用程序?

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.

*实际上,我猜 build 本身可能已经完成,但 VisualStudio 从不运行应用程序,只是挂起等待脚本退出.

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

推荐答案

将 watch Bindings 更改为 Project Open.然后在项目打开后开始观看.

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

这篇关于在后台使用 npm watch 文件以启用与 Visual Studio Task Runner 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆