diff --git a/contributors.yml b/contributors.yml index a708c85daf8..1aaefc48072 100644 --- a/contributors.yml +++ b/contributors.yml @@ -62,6 +62,7 @@ - chenxsan - chiangs - christianhg +- christophertrudel - christophgockel - clarkmitchell - cliffordfajardo diff --git a/docs/api/conventions.md b/docs/api/conventions.md index ef7a9028ea2..7ededcc0074 100644 --- a/docs/api/conventions.md +++ b/docs/api/conventions.md @@ -158,6 +158,18 @@ module.exports = { }; ``` +### watchPaths + +A function for defining custom directories to watch while running [remix dev](https://remix.run/docs/en/v1/other-api/dev#remix-dev), in addition to [`appDirectory`](#appDirectory). + +```tsx +exports.watchPaths = async () => { + return [ + "/some/path/*" + ]; +}; +``` + ## File Name Conventions There are a few conventions that Remix uses you should be aware of. diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts index 92af7767d63..5164cc96066 100644 --- a/packages/remix-dev/__tests__/readConfig-test.ts +++ b/packages/remix-dev/__tests__/readConfig-test.ts @@ -48,6 +48,7 @@ describe("readConfig", () => { "serverMode": "production", "serverModuleFormat": "cjs", "serverPlatform": "node", + "watchPaths": Array [], } ` ); diff --git a/packages/remix-dev/compiler.ts b/packages/remix-dev/compiler.ts index 39209f2bc3e..61b828427bc 100644 --- a/packages/remix-dev/compiler.ts +++ b/packages/remix-dev/compiler.ts @@ -221,6 +221,10 @@ export async function watch( if (config.serverEntryPoint) { toWatch.push(config.serverEntryPoint); } + + config.watchPaths?.forEach((watchPath) => { + toWatch.push(watchPath); + }); let watcher = chokidar .watch(toWatch, { diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index fae6c171bf0..4318375d793 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -147,6 +147,14 @@ export interface AppConfig { * in a CJS build. */ serverDependenciesToBundle?: Array; + + /** + * A function for defining custom directories to watch while running `remix dev`, in addition to `appDirectory`. + */ + watchPaths?: + | string + | string[] + | (() => Promise | string | string[]); } /** @@ -250,6 +258,11 @@ export interface RemixConfig { * in a CJS build. */ serverDependenciesToBundle: Array; + + /** + * A list of directories to watch. + */ + watchPaths: string[]; } /** @@ -395,6 +408,20 @@ export async function readConfig( } } + let watchPaths: string[] = []; + if (typeof appConfig.watchPaths === "function") { + let directories = await appConfig.watchPaths(); + watchPaths = watchPaths.concat( + Array.isArray(directories) ? directories : [directories] + ); + } else if (appConfig.watchPaths) { + watchPaths = watchPaths.concat( + Array.isArray(appConfig.watchPaths) + ? appConfig.watchPaths + : [appConfig.watchPaths] + ); + } + let serverBuildTargetEntryModule = `export * from ${JSON.stringify( serverBuildVirtualModule.id )};`; @@ -421,6 +448,7 @@ export async function readConfig( serverEntryPoint: customServerEntryPoint, serverDependenciesToBundle, mdx, + watchPaths, }; }