| 1 |
# The watch command |
| 2 |
|
| 3 |
The `watch` command is useful when you want your book to be rendered on every |
| 4 |
file change. You could repeatedly issue `mdbook build` every time a file is |
| 5 |
changed. But using `mdbook watch` once will watch your files and will trigger a |
| 6 |
build automatically whenever you modify a file; this includes re-creating |
| 7 |
deleted files still mentioned in `SUMMARY.md`! |
| 8 |
|
| 9 |
#### Specify a directory |
| 10 |
|
| 11 |
The `watch` command can take a directory as an argument to use as the book's |
| 12 |
root instead of the current working directory. |
| 13 |
|
| 14 |
```bash |
| 15 |
mdbook watch path/to/book |
| 16 |
``` |
| 17 |
|
| 18 |
#### `--open` |
| 19 |
|
| 20 |
When you use the `--open` (`-o`) option, mdbook will open the rendered book in |
| 21 |
your default web browser. |
| 22 |
|
| 23 |
#### `--dest-dir` |
| 24 |
|
| 25 |
The `--dest-dir` (`-d`) option allows you to change the output directory for the |
| 26 |
book. Relative paths are interpreted relative to the current directory. If |
| 27 |
not specified it will default to the value of the `build.build-dir` key in |
| 28 |
`book.toml`, or to `./book`. |
| 29 |
|
| 30 |
{{#include arg-watcher.md}} |
| 31 |
|
| 32 |
#### Specify exclude patterns |
| 33 |
|
| 34 |
The `watch` command will not automatically trigger a build for files listed in |
| 35 |
the `.gitignore` file in the book root directory. The `.gitignore` file may |
| 36 |
contain file patterns described in the [gitignore |
| 37 |
documentation](https://git-scm.com/docs/gitignore). This can be useful for |
| 38 |
ignoring temporary files created by some editors. |
| 39 |
|
| 40 |
_Note: Only `.gitignore` from book root directory is used. Global |
| 41 |
`$HOME/.gitignore` or `.gitignore` files in parent directories are not used._ |