Skip to content

Commit

Permalink
Only add Remix packages to ssr.external in Remix repo (#9301)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Apr 24, 2024
1 parent c5eda9a commit 4e98f41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-donuts-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Fix issue where consumers who had added Remix packages to Vite's `ssr.noExternal` option were being overridden by the Remix Vite plugin adding Remix packages to Vite's `ssr.external` option.
44 changes: 26 additions & 18 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,24 +1054,26 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
: "custom",

ssr: {
external: [
// This is only necessary for development within the Remix repo
// because these packages are symlinked and Vite treats them as
// internal source code. For consumers this is a no-op.
"@remix-run/architect",
"@remix-run/cloudflare-pages",
"@remix-run/cloudflare-workers",
"@remix-run/cloudflare",
"@remix-run/css-bundle",
"@remix-run/deno",
"@remix-run/dev",
"@remix-run/express",
"@remix-run/netlify",
"@remix-run/node",
"@remix-run/react",
"@remix-run/serve",
"@remix-run/server-runtime",
],
external: isInRemixMonorepo()
? [
// This is only needed within the Remix repo because these
// packages are linked to a directory outside of node_modules
// so Vite treats them as internal code by default.
"@remix-run/architect",
"@remix-run/cloudflare-pages",
"@remix-run/cloudflare-workers",
"@remix-run/cloudflare",
"@remix-run/css-bundle",
"@remix-run/deno",
"@remix-run/dev",
"@remix-run/express",
"@remix-run/netlify",
"@remix-run/node",
"@remix-run/react",
"@remix-run/serve",
"@remix-run/server-runtime",
]
: undefined,
},
optimizeDeps: {
include: [
Expand Down Expand Up @@ -1771,6 +1773,12 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
];
};

function isInRemixMonorepo() {
let devPath = path.dirname(require.resolve("@remix-run/dev/package.json"));
let devParentDir = path.basename(path.resolve(devPath, ".."));
return devParentDir === "packages";
}

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

0 comments on commit 4e98f41

Please sign in to comment.