有没有一种方法可以使用npm脚本运行tsc -watch&& nodemon-看吗? [英] Is there a way to use npm scripts to run tsc -watch && nodemon --watch?
问题描述
我正在寻找一种使用npm脚本同时运行tsc --watch && nodemon --watch
的方法.我可以独立运行此命令,但是当我要同时运行它们时,仅执行第一个命令.
例如.
如果我有这个脚本:
I'm looking for a way to use npm scripts to run tsc --watch && nodemon --watch
at the same time. I can run this commands independently, but when I want run both of them, only the first one is executed.
eg.
if I have this script:
"scripts": {
"runDeb": "set NODE_ENV=development&& tsc --watch && nodemon --watch"
}
tsc --watch
已执行,但从未调用nodemon
,反之亦然.
tsc --watch
is executed but nodemon
is never called, and vice versa.
推荐答案
我认为您想要的是这样的东西(我当前的设置):
I think what you want is something like this (my current setup):
"scripts": {
"compile": "tsc && node app.js",
"dev": "./node_modules/nodemon/bin/nodemon.js -e ts --exec \"npm run compile\""
}
我创建了两个脚本"compile"和"dev".要开始开发,您只需运行npm run dev
即可启动nodemon并使其监视.ts文件(使用-e
标志).然后,每次.ts文件更改nodemon都会exec
基本上执行并运行节点应用程序的编译任务.
I created two scripts "compile" and "dev". To start developing you simply run npm run dev
which starts nodemon and makes it watch .ts files (using the -e
flag). Then, every time a .ts file changes nodemon will exec
the compile task which basically compiles and runs the node app.
虽然并发使用是一个不错的选择,但我的设置可以保证tsc
的工作已在尝试执行生成的.js文件之前完成.
While using concurrently is a good option, my setup guarantees that tsc
's work is done before attempting to execute the resulting .js files.
这篇关于有没有一种方法可以使用npm脚本运行tsc -watch&& nodemon-看吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!