Skip to content

watchDirectory

In development, watchDirectory will reload the Astro dev server if any files within the directory change. For example:

my-integration/index.ts
1
import {
2
defineIntegration,
3
createResolver,
4
watchDirectory
5
} from "astro-integration-kit";
6
7
export default defineIntegration({
8
// ...
9
setup() {
10
const { resolve } = createResolver(import.meta.url)
11
12
return {
13
hooks: {
14
"astro:config:setup": (params) => {
15
watchDirectory(params, resolve())
16
}
17
}
18
}
19
}
20
})

Limitations

Those are due to limitations in Astro core:

  1. This utility watches all files deeply under the specified directory
  2. Only files are considered. Directories themselves are not watched (eg. an empty folder is deleted)
  3. Files added to the directory won’t cause a reload and won’t be watched for further changes until one of the old files is changed or the dev server is restarted