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

Only add RR packages to ssr.external in RR repo #11489

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Changes from all commits
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
50 changes: 32 additions & 18 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,24 +1048,26 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
: "custom",

ssr: {
external: [
// This is only necessary for development within this repo
// because these packages are symlinked and Vite treats them as
// internal source code. For consumers this is a no-op.
"react-router",
"react-router-dom",
"@react-router/architect",
"@react-router/cloudflare-pages",
"@react-router/cloudflare-workers",
"@react-router/cloudflare",
"@react-router/deno",
"@react-router/dev",
"@react-router/express",
"@react-router/netlify",
"@react-router/node",
"@react-router/serve",
"@react-router/server-runtime",
],
external: isInReactRouterMonorepo()
? [
// This is only needed within this repo because these packages
// are linked to a directory outside of node_modules so Vite
// treats them as internal code by default.
"react-router",
"react-router-dom",
"@react-router/architect",
"@react-router/cloudflare-pages",
"@react-router/cloudflare-workers",
"@react-router/cloudflare",
"@react-router/deno",
"@react-router/dev",
"@react-router/express",
"@react-router/netlify",
"@react-router/node",
"@react-router/serve",
"@react-router/server-runtime",
]
: undefined,
},
optimizeDeps: {
include: [
Expand Down Expand Up @@ -1779,6 +1781,18 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
];
};

function isInReactRouterMonorepo() {
// We use '@react-router/server-runtime' for this check since it's a
// dependency of this package and guaranteed to be in node_modules
let serverRuntimePath = path.dirname(
require.resolve("@react-router/server-runtime/package.json")
);
let serverRuntimeParentDir = path.basename(
path.resolve(serverRuntimePath, "..")
);
return serverRuntimeParentDir === "packages";
}

function isEqualJson(v1: unknown, v2: unknown) {
return JSON.stringify(v1) === JSON.stringify(v2);
}
Expand Down
Loading