Add support for watching additional directories #1884
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using mdBook preprocessors like mdbook-quiz, the book depends on files outside the source directory, such as TOML files describing quizzes. It would be very convenient as an author for the book to automatically rebuild when these files change. However, the
watch
andserve
commands (viatrigger_on_change
) only watch a fixed set of directories.Probably the ideal solution would be for preprocessors to register files to be watched, similar to how extensible build systems like esbuild manage plugins. However, this would be a big change with a lot of work. A much cheaper solution is to allow mdbook CLI users to pass desired directories-to-watch on the command line.
Therefore this PR adds a new flag to
watch
andserve
,--extra-watch-dirs
. For example, a user could write:The
--extra-watch-dirs
flag takes as input a comma-separated list of directories. Each of these directories is added to the file watcher, so the book is regenerated when a file in these directories is changed.