Skip to content

Commit 9042a5c

Browse files
committed
Move ssrExternals into config directory
1 parent d266ff3 commit 9042a5c

File tree

3 files changed

+29
-31
lines changed

3 files changed

+29
-31
lines changed

packages/react-router-dev/config/config.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
configRoutesToRouteManifest,
2323
} from "./routes";
2424
import { detectPackageManager } from "../cli/detectPackageManager";
25-
import { ssrExternals } from "../vite/ssr-externals";
2625

2726
const excludedConfigPresetKeys = ["presets"] as const satisfies ReadonlyArray<
2827
keyof ReactRouterConfig
@@ -702,6 +701,34 @@ export async function resolveEntryFiles({
702701
return { entryClientFilePath, entryServerFilePath };
703702
}
704703

704+
export const ssrExternals = isInReactRouterMonorepo()
705+
? [
706+
// This is only needed within this repo because these packages
707+
// are linked to a directory outside of node_modules so Vite
708+
// treats them as internal code by default.
709+
"react-router",
710+
"react-router-dom",
711+
"@react-router/architect",
712+
"@react-router/cloudflare",
713+
"@react-router/dev",
714+
"@react-router/express",
715+
"@react-router/node",
716+
"@react-router/serve",
717+
]
718+
: undefined;
719+
720+
function isInReactRouterMonorepo() {
721+
// We use '@react-router/node' for this check since it's a
722+
// dependency of this package and guaranteed to be in node_modules
723+
let serverRuntimePath = path.dirname(
724+
require.resolve("@react-router/node/package.json")
725+
);
726+
let serverRuntimeParentDir = path.basename(
727+
path.resolve(serverRuntimePath, "..")
728+
);
729+
return serverRuntimeParentDir === "packages";
730+
}
731+
705732
const entryExts = [".js", ".jsx", ".ts", ".tsx"];
706733

707734
function findEntry(

packages/react-router-dev/vite/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import {
3939
type ResolvedReactRouterConfig,
4040
createConfigLoader,
4141
resolveEntryFiles,
42+
ssrExternals,
4243
} from "../config/config";
43-
import { ssrExternals } from "./ssr-externals";
4444
import * as WithProps from "./with-props";
4545

4646
export async function resolveViteConfig({

packages/react-router-dev/vite/ssr-externals.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)