Compiles your TS app and restarts when files are modified.
It restarts target node process when any of required files changes (as standard
node-dev) but shares Typescriptcompilation process between restarts. This significantly increases speed of restarting comparing to
node-dev -r ts-node/register ...,
nodemon -x ts-node ...variations because there is no need to instantiate
ts-nodecompilation each time.
yarn add ts-node-dev --dev
npm i ts-node-dev --save-dev
ts-nodedependency version is not fixed, so it will install the latest version by default.
ts-node-dev [node-dev|ts-node flags] [ts-node-dev flags] [node cli flags] [--] [script] [script arguments]
ts-node-dev --respawn --transpileOnly server.ts
There is also short alias
tsnd --respawn server.ts
Also there are additional options specific to
--prefer-ts(default: false) - for each
.jsfile (that is not in
node_modules) will try to check if corresponding
.tsversion exists and require it.
--ignore-watch(default: ) - files/folders to be ignored by
node-dev. But also this behaviour enhanced:it will also make up
new RegExpof passed ignore string and check absolute paths of required files for match. So, to ignore everything in
node_modules, just pass
--debug- Some additional debug output.
--interval- Polling interval (ms)
--debounce- Debounce file change events (ms, non-polling mode)
--cls) Will clear screen on restart
--watch- Explicitly add files or folders to watch and restart on change (list separated by commas)
--exit-child- Adds 'SIGTERM' exit handler in a child process.
Caveats and points of notice:
Especially for large code bases always consider running with
--transpile-onlyflag which is normal for dev workflow and will speed up things greatly. Note, that
ts-node-devwill not put watch handlers on TS files that contain only types/interfaces (used only for type checking) - this is current limitation by design.
--ignore-watchwill NOT affect files ignored by TS compilation. Use
TS_NODE_IGNOREenv variable) to pass RegExp stringsfor filtering files that should not be compiled, by default
Unknown flags (
nodecli flags are considered to be so) are treated like string value flags by default. The right solution to avoid ambiguity is to separate script name from option flags with
--, for example:
ts-node-dev --inspect -- my-script.ts
The good thing is that
tsconfig.jsonfile, and will reinitialize compilation on its change, but you have to restart the process manually when you update used version of
typescriptor make any other changes that may effect compilation results.
以上是 @floydophone/ts-node-dev 的使用教程帮助文档。