Watch mode and HMR
Ende has a built-in file watcher, so you don't need nodemon or any other
external tool to reload your program as you edit. This page covers what gets
watched, how to exclude paths, and hot module replacement.
Watch mode
You can supply the --watch flag to ende run, ende test, and ende fmt to
enable the built-in file watcher. The watcher enables automatic reloading of
your application whenever changes are detected in the source files. This is
particularly useful during development, as it allows you to see the effects of
your changes immediately without manually restarting the application.
ende run --watch main.ts
ende test --watch
ende fmt --watch
The files that are watched will depend on the subcommand used:
- for
ende runandende testthe entrypoint, and all local files that the entrypoint statically imports will be watched. - for
ende fmtall local files and directories specified as command line arguments (or the working directory if no specific files/directories is passed) are watched.
You can exclude paths or patterns from watching by providing the
--watch-exclude flag. The syntax is --watch-exclude=path1,path2. For
example:
ende run --watch --watch-exclude=file1.ts,file2.ts main.ts
This will exclude file1.ts and file2.ts from being watched.
To exclude a pattern, remember to surround it in quotes to prevent your shell from expanding the glob:
ende run --watch --watch-exclude='*.js' main.ts
Hot module replacement
ende run also supports the --watch-hmr flag, which hot-replaces changed
modules in the running process instead of restarting it. This keeps your
application's state across edits. If hot replacement fails, the process falls
back to a full restart.
ende run --watch-hmr main.ts
Because this is such a common development workflow,
ende watch is a shorthand for
ende run --watch-hmr:
ende watch main.ts
Editors with atomic save
Some editors use "atomic save" (also called safe write), where the editor writes
your changes to a temporary file and then renames it over the original on each
save. On Linux this replaces the file with a new one on disk, which can detach
the file watcher used by --watch-hmr after the first change. The symptom is
that hot replacement works once and then stops detecting further edits to that
module.
If you hit this, disable atomic save in your editor:
- Helix: set
[editor] atomic-save = false(it is enabled by default). - Neovim/Vim: set
:set backupcopy=yes.
Plain --watch is not affected, because each change triggers a full restart
that re-establishes the watchers.