Skip to content

Commit

Permalink
feat(remix-dev): watchDirectories option for remix.config
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Trudel committed Jun 8, 2022
1 parent c2f6bf4 commit 1c6df03
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/api/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ module.exports = {
};
```

### watchDirectories

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.watchDirectories = async () => {
return [
"/some/path/*"
];
};
```

## File Name Conventions

There are a few conventions that Remix uses you should be aware of.
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("readConfig", () => {
"serverMode": "production",
"serverModuleFormat": "cjs",
"serverPlatform": "node",
"watchDirectories": Array [],
}
`
);
Expand Down
4 changes: 4 additions & 0 deletions packages/remix-dev/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ export async function watch(
if (config.serverEntryPoint) {
toWatch.push(config.serverEntryPoint);
}

config.watchDirectories?.forEach((directory) => {
toWatch.push(directory);
});

let watcher = chokidar
.watch(toWatch, {
Expand Down
17 changes: 17 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ export interface AppConfig {
* in a CJS build.
*/
serverDependenciesToBundle?: Array<string | RegExp>;

/**
* A function for defining custom directories to watch while running `remix dev`, in addition to `appDirectory`.
*/
watchDirectories?: () => Promise<string | string[]>;
}

/**
Expand Down Expand Up @@ -250,6 +255,11 @@ export interface RemixConfig {
* in a CJS build.
*/
serverDependenciesToBundle: Array<string | RegExp>;

/**
* A list of directories to watch.
*/
watchDirectories: string[];
}

/**
Expand Down Expand Up @@ -395,6 +405,12 @@ export async function readConfig(
}
}

let watchDirectories: string[] = [];
if (appConfig.watchDirectories) {
let directories = await appConfig.watchDirectories();
watchDirectories = watchDirectories.concat(Array.isArray(directories) ? directories : [directories]);
}

let serverBuildTargetEntryModule = `export * from ${JSON.stringify(
serverBuildVirtualModule.id
)};`;
Expand All @@ -421,6 +437,7 @@ export async function readConfig(
serverEntryPoint: customServerEntryPoint,
serverDependenciesToBundle,
mdx,
watchDirectories,
};
}

Expand Down

0 comments on commit 1c6df03

Please sign in to comment.