Skip to content

Commit

Permalink
feat(remix-dev): add suppport for .mjs and .cjs configs (#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey authored and mcansh committed Aug 11, 2022
1 parent e1ec2b5 commit 6c19f72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-peaches-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Add support for .mjs and .cjs remix.config files.
32 changes: 23 additions & 9 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,18 @@ export async function readConfig(
}

let rootDirectory = path.resolve(remixRoot);
let configFile = path.resolve(rootDirectory, "remix.config.js");

let appConfig: AppConfig;
try {
appConfig = require(configFile);
} catch (error) {
throw new Error(
`Error loading Remix config in ${configFile}\n${String(error)}`
);
let configFile = findConfig(rootDirectory, "remix.config");

let appConfig: AppConfig = {};
if (configFile) {
try {
let appConfigModule = await import(configFile);
appConfig = appConfigModule?.default || appConfig;
} catch (error) {
throw new Error(
`Error loading Remix config at ${configFile}\n${String(error)}`
);
}
}

let customServerEntryPoint = appConfig.server;
Expand Down Expand Up @@ -475,3 +478,14 @@ function findEntry(dir: string, basename: string): string | undefined {

return undefined;
}

const configExts = [".js", ".cjs", ".mjs"];

function findConfig(dir: string, basename: string): string | undefined {
for (let ext of configExts) {
let file = path.resolve(dir, basename + ext);
if (fse.existsSync(file)) return file;
}

return undefined;
}

0 comments on commit 6c19f72

Please sign in to comment.