Skip to content

Commit

Permalink
Fix dest already exists error during Vite build (#11501)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Apr 26, 2024
1 parent f322d47 commit 221a2c9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
return JSON.parse(manifestContents) as Vite.Manifest;
};

let getViteManifestFilePaths = (viteManifest: Vite.Manifest): Set<string> => {
let filePaths = Object.values(viteManifest).map((chunk) => chunk.file);
return new Set(filePaths);
};

let getViteManifestAssetPaths = (
viteManifest: Vite.Manifest
): Set<string> => {
Expand Down Expand Up @@ -1405,7 +1410,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
let ssrViteManifest = await loadViteManifest(serverBuildDirectory);
let clientViteManifest = await loadViteManifest(clientBuildDirectory);

let clientAssetPaths = getViteManifestAssetPaths(clientViteManifest);
let clientFilePaths = getViteManifestFilePaths(clientViteManifest);
let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);

// We only move assets that aren't in the client build, otherwise we
Expand All @@ -1417,7 +1422,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
let movedAssetPaths: string[] = [];
for (let ssrAssetPath of ssrAssetPaths) {
let src = path.join(serverBuildDirectory, ssrAssetPath);
if (!clientAssetPaths.has(ssrAssetPath)) {
if (!clientFilePaths.has(ssrAssetPath)) {
let dest = path.join(clientBuildDirectory, ssrAssetPath);
await fse.move(src, dest);
movedAssetPaths.push(dest);
Expand Down

0 comments on commit 221a2c9

Please sign in to comment.