如何在打字稿文件更改时观察和重新加载ts-node [英] How to watch and reload ts-node when typescript file changes

查看:186
本文介绍了如何在打字稿文件更改时观察和重新加载ts-node的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用typescript和angular2应用程序运行一个开发服务器,但没有每次都检测ts文件,我发现我可以用ts-node来运行,但我也想看.ts文件并重新加载应用程序/服务器因为我会用吞咽手表之类的东西。

解决方案

我一直在为我的开发环境苦苦挣扎,直到我注意到nodemon的api允许我们改变它的默认行为为了执行自定义命令。一个例子如下所示:

  nodemon --watch'src / ** / *。ts'--ignore 'src / ** / *。spec.ts'--exec'ts-node'src / index.ts 

或者更好的并且将nodemon的配置外部化,因为Sandokan通过以下内容获取到nodemon.json文件,然后运行nodemon:

  {watch:[src / ** / *。ts],ignore:[src / ** / *。spec.ts],exec:ts-node ./index.ts} 

凭借这样做,您可以实时重新加载一个ts节点过程,而不必担心底层的实现。



干杯!



已更新对于最新版本的nodemon:



使用以下内容创建一个nomdemon.json文件。



< pre $
$ watch $ $ b $ ex $ $ $ $ $ $ $ $ $ $ $'$' ** / *。spec.ts],
exec:ts-node ./src/index.ts
}


Im trying to run a dev server with typescript and an angular2 application without transpiling ts files every time, I found that i can do the running with ts-node but i want also to watch .ts files and reload the app/server as i would do with something like gulp watch.

解决方案

I was struggling with the same thing for my development environment until i noticed that nodemon's api allows us to change it's default behaviour in order to execute a custom command. An example of this would be like follows:

nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts

Or even better and externalize nodemon's config as Sandokan sugested to a nodemon.json file with the following content, and then just run nodemon:

{ "watch": ["src/**/*.ts"], "ignore": ["src/**/*.spec.ts"], "exec": "ts-node ./index.ts" }

By virtue of doing this you'll be able to live-reload a ts-node process without having to worry about the underlying implementation.

Cheers!

Updated for most recent version of nodemon:

Create a nomdemon.json file with the following content.

{
  "watch": ["src"],
  "ext": "ts",
  "ignore": ["src/**/*.spec.ts"],
  "exec": "ts-node ./src/index.ts"
}

这篇关于如何在打字稿文件更改时观察和重新加载ts-node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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