Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(remix-dev): add watchPaths config option #3188

Merged
merged 4 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better!

| 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