watchDirectory
In development, watchDirectory
will reload the Astro dev server if any files within
the directory change. For example:
1import {2 defineIntegration,3 createResolver,4 watchDirectory5} from "astro-integration-kit";6
7export 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:
- 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