watchDirectory
In development, watchDirectory
will reload the Astro dev server if any files within
the directory change. For example:
import { defineIntegration, createResolver, watchDirectory} from "astro-integration-kit";
export default defineIntegration({ // ... setup() { const { resolve } = createResolver(import.meta.url)
return { hooks: { "astro:config:setup": (params) => { watchDirectory(params, resolve()) } } } }})
Limitations
Section titled “Limitations”Those are due to limitations in Astro core:
- This utility watches all files deeply under the specified directory
- Only files are considered. Directories themselves are not watched (eg. an empty folder is deleted)
- 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