Skip to content

Commit

Permalink
feat(remix-dev): add watchPaths config option (#3188)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Trudel <[email protected]>
Co-authored-by: Jacob Ebey <[email protected]>
  • Loading branch information
3 people authored Jun 30, 2022
1 parent f6108eb commit bbe8d11
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- chenxsan
- chiangs
- christianhg
- christophertrudel
- christophgockel
- clarkmitchell
- cliffordfajardo
Expand Down
12 changes: 12 additions & 0 deletions docs/api/conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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",
"watchPaths": 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 @@ -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, {
Expand Down
28 changes: 28 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ 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`.
*/
watchPaths?:
| string
| string[]
| (() => Promise<string | string[]> | string | string[]);
}

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

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

/**
Expand Down Expand Up @@ -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
)};`;
Expand All @@ -421,6 +448,7 @@ export async function readConfig(
serverEntryPoint: customServerEntryPoint,
serverDependenciesToBundle,
mdx,
watchPaths,
};
}

Expand Down

0 comments on commit bbe8d11

Please sign in to comment.