Skip to content

Commit

Permalink
Inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jan 3, 2025
1 parent 67e897d commit bf8b2d5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/remix-dev/vite/vite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// This file serves two purposes. First, it's used to avoid CJS deprecation
// warnings in Vite since `@remix-run/dev` currently compiles to CJS. We do this
// by dynamically importing Vite, forcing it to use the ESM build. Second, it's
// used to allow us to test against different versions of Vite by ensuring that
// Vite is resolved from the current working directory when running within this
// repo. If we don't do this, Vite will always be imported relative to this
// package, which means that it will always resolve to Vite 6.

import path from "pathe";

import invariant from "../invariant";
Expand All @@ -15,15 +7,21 @@ import { isInRemixMonorepo } from "./is-in-remix-monorepo";
type Vite = typeof import("vite");
let vite: Vite | undefined;

const viteImportSpecifier = !isInRemixMonorepo()
? "vite"
: `file:///${path
const viteImportSpecifier = isInRemixMonorepo()
? // Support testing against different versions of Vite by ensuring that Vite
// is resolved from the current working directory when running within this
// repo. If we don't do this, Vite will always be imported relative to this
// file, which means that it will always resolve to Vite 6.
`file:///${path
.normalize(
require.resolve("vite/package.json", { paths: [process.cwd()] })
)
.replace("package.json", "dist/node/index.js")}`;
.replace("package.json", "dist/node/index.js")}`
: "vite";

export async function preloadVite(): Promise<void> {
// Use a dynamic import to force Vite to use the ESM build. If we don't do
// this, Vite logs CJS deprecation warnings.
vite = await import(viteImportSpecifier);
}

Expand Down

0 comments on commit bf8b2d5

Please sign in to comment.