如何在打字稿文件更改时观察和重新加载ts-node [英] How to watch and reload ts-node when typescript file changes
问题描述
我一直在为我的开发环境苦苦挣扎,直到我注意到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屋!