Skip to content

Instantly share code, notes, and snippets.

@kiliman
Created May 19, 2022 19:08
Show Gist options
  • Save kiliman/925b33a48b20b57520053d3da091e504 to your computer and use it in GitHub Desktop.
Save kiliman/925b33a48b20b57520053d3da091e504 to your computer and use it in GitHub Desktop.
Remix patch to add additional watch directories (see PR #3188)
diff --git a/node_modules/@remix-run/dev/compiler.js b/node_modules/@remix-run/dev/compiler.js
index 902b251..9b6c54d 100644
--- a/node_modules/@remix-run/dev/compiler.js
+++ b/node_modules/@remix-run/dev/compiler.js
@@ -210,7 +210,10 @@ async function watch(config$1, {
if (config$1.serverEntryPoint) {
toWatch.push(config$1.serverEntryPoint);
}
-
+ config$1.watchDirectories?.forEach((directory) => {
+ toWatch.push(directory);
+ });
+ console.log('watching directories:', toWatch);
let watcher = chokidar__default["default"].watch(toWatch, {
persistent: true,
ignoreInitial: true,
diff --git a/node_modules/@remix-run/dev/config.js b/node_modules/@remix-run/dev/config.js
index 5aede25..074b351 100644
--- a/node_modules/@remix-run/dev/config.js
+++ b/node_modules/@remix-run/dev/config.js
@@ -182,6 +182,11 @@ async function readConfig(remixRoot, serverMode = serverModes.ServerMode.Product
};
}
}
+ let watchDirectories = [];
+ if (appConfig.watchDirectories) {
+ let directories = await appConfig.watchDirectories();
+ watchDirectories = watchDirectories.concat(Array.isArray(directories) ? directories : [directories]);
+ }
let serverBuildTargetEntryModule = `export * from ${JSON.stringify(virtualModules.serverBuildVirtualModule.id)};`;
let serverDependenciesToBundle = appConfig.serverDependenciesToBundle || [];
@@ -204,7 +209,8 @@ async function readConfig(remixRoot, serverMode = serverModes.ServerMode.Product
serverBuildTargetEntryModule,
serverEntryPoint: customServerEntryPoint,
serverDependenciesToBundle,
- mdx
+ mdx,
+ watchDirectories,
};
}

This patch adds watchDirectories to the remix.config file. Use this patch until PR #3188 lands

NOTE: watchDirectories is an async function that returns an array of directories.

module.exports = {
  ignoredRouteFiles: ['**/components/*'],
  watchDirectories: () => ['node_modules/@remix-run'],
}

Copy the patch file to /patches folder. Install patch-package and update postinstall to run patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment