Skip to content

Commit

Permalink
restart dev server on Remix config change
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Aug 29, 2023
1 parent fd6060c commit 6aac9e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/restart-dev-server-on-remix-config-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Restart dev server when Remix config changes
7 changes: 5 additions & 2 deletions packages/remix-dev/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { normalizeSlashes } from "../config/routes";
import type { Manifest } from "../manifest";

function isEntryPoint(config: RemixConfig, file: string): boolean {
let configFile = path.join(config.rootDirectory, "remix.config.js");
let appFile = path.relative(config.appDirectory, file);
let entryPoints = [
configFile,
config.entryClientFile,
config.entryServerFile,
...Object.values(config.routes).map((route) => route.file),
Expand Down Expand Up @@ -98,7 +100,8 @@ export async function watch(
onBuildFinish?.(ctx, Date.now() - start, manifest !== undefined);
}, 100);

let toWatch = [ctx.config.appDirectory];
let remixConfigPath = path.join(ctx.config.rootDirectory, "remix.config.js");
let toWatch = [remixConfigPath, ctx.config.appDirectory];

// WARNING: Chokidar returns different paths in change events depending on
// whether the path provided to the watcher is absolute or relative. If the
Expand Down Expand Up @@ -127,7 +130,7 @@ export async function watch(
.on("change", async (file) => {
if (shouldIgnore(file)) return;
onFileChanged?.(file);
await rebuild();
await (file === remixConfigPath ? restart : rebuild)();
})
.on("add", async (file) => {
if (shouldIgnore(file)) return;
Expand Down
5 changes: 4 additions & 1 deletion packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ export async function readConfig(
// https://github.com/nodejs/node/issues/35889
appConfigModule = require(configFile);
} else {
appConfigModule = await import(pathToFileURL(configFile).href);
let stat = fse.statSync(configFile);
appConfigModule = await import(
pathToFileURL(configFile).href + "?t=" + stat.mtimeMs
);
}
appConfig = appConfigModule?.default || appConfigModule;
} catch (error: unknown) {
Expand Down

0 comments on commit 6aac9e0

Please sign in to comment.