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 suppport for .mjs and .cjs configs #3675

Merged
merged 4 commits into from
Aug 4, 2022
Merged
Changes from 1 commit
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
32 changes: 23 additions & 9 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,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 in ${configFile}\n${String(error)}`
);
}
}

let customServerEntryPoint = appConfig.server;
Expand Down Expand Up @@ -466,3 +469,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 path.relative(dir, file);
}

return undefined;
}