Skip to content

Commit

Permalink
fix(remix-dev/vite): remove Vite v4 back compat
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jan 23, 2024
1 parent 0bc6c12 commit f47ed15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-mice-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Vite: Remove undocumented backwards compatibility layer for Vite v4
24 changes: 3 additions & 21 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,6 @@ const getServerBundleBuildConfig = (
return viteUserConfig.__remixServerBundleBuildConfig as ServerBundleBuildConfig;
};

const getViteMajorVersion = (): number => {
let vitePkg = require("vite/package.json");
return parseInt(vitePkg.version.split(".")[0]!);
};

export let getServerBuildDirectory = (remixConfig: ResolvedVitePluginConfig) =>
path.join(
remixConfig.buildDirectory,
Expand All @@ -428,8 +423,6 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
let viteUserConfig: Vite.UserConfig;
let viteConfig: Vite.ResolvedConfig | undefined;

let isViteV4 = getViteMajorVersion() === 4;

let cssModulesManifest: Record<string, string> = {};
let ssrBuildContext:
| { isSsrBuild: false }
Expand Down Expand Up @@ -586,11 +579,8 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
};

let loadViteManifest = async (directory: string) => {
let manifestPath = isViteV4
? "manifest.json"
: path.join(".vite", "manifest.json");
let manifestContents = await fse.readFile(
path.resolve(directory, manifestPath),
path.resolve(directory, ".vite", "manifest.json"),
"utf-8"
);
return JSON.parse(manifestContents) as Vite.Manifest;
Expand Down Expand Up @@ -731,12 +721,6 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
)
);

let isSsrBuild =
"ssrBuild" in viteConfigEnv &&
typeof viteConfigEnv.ssrBuild === "boolean"
? viteConfigEnv.ssrBuild // Vite v4 back compat
: viteConfigEnv.isSsrBuild;

return {
__remixPluginResolvedConfig: remixConfig,
appType: "custom",
Expand Down Expand Up @@ -784,7 +768,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
base: remixConfig.publicPath,
build: {
...viteUserConfig.build,
...(!isSsrBuild
...(!viteConfigEnv.isSsrBuild
? {
manifest: true,
outDir: getClientBuildDirectory(remixConfig),
Expand Down Expand Up @@ -862,9 +846,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
{
command: viteConfig.command,
mode: viteConfig.mode,
...(isViteV4
? { ssrBuild: ssrBuildContext.isSsrBuild }
: { isSsrBuild: ssrBuildContext.isSsrBuild }),
isSsrBuild: ssrBuildContext.isSsrBuild,
},
viteConfig.configFile
);
Expand Down

0 comments on commit f47ed15

Please sign in to comment.