docs/watch-mode.md
::: warning Not to be confused with Node's Watch mode
tsx introduced Watch mode before Node.js released the --watch flag in v18.11.0. Although it is similar in functionality, it does not yet match the robustness of tsx's Watch mode.
:::
Watch mode will automatically re-run your script whenever any of its dependencies are changed.
tsx watch ./file.ts
By default, tsx watches all imported files, except those in the following directories:
node_modulesbower_componentsvendordist.*)To include specific files or directories to watch, use the --include flag:
tsx watch --include ./other-dep.txt --include "./other-deps/*" ./file.ts
To exclude specific files from being watched, use the --exclude flag:
tsx watch --exclude ./ignore-me.js --exclude ./ignore-me-too.js ./file.ts
Glob patterns allow you to define a set of files or directories to ignore. To prevent your shell from expanding the glob patterns, wrap them in quotes:
tsx watch --exclude "./data/**/*" ./file.ts
--clear-screen=false to prevent the screen from clearing on rerun.