-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(remix-dev/vite): remove Vite wrapper functions (#8120)
- Loading branch information
1 parent
a704b26
commit 497eea8
Showing
9 changed files
with
94 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
"@remix-run/dev": patch | ||
--- | ||
|
||
Remove `unstable_createViteServer` and `unstable_loadViteServerBuild` which were only minimal wrappers around Vite's `createServer` and `ssrLoadModule` functions when using a custom server. | ||
|
||
**This is a breaking change for projects using the unstable Vite plugin with a custom server.** | ||
|
||
Instead, we now provide `unstable_viteServerBuildModuleId` so that custom servers interact with Vite directly rather than via Remix APIs, for example: | ||
|
||
```diff | ||
-import { | ||
- unstable_createViteServer, | ||
- unstable_loadViteServerBuild, | ||
-} from "@remix-run/dev"; | ||
+import { unstable_viteServerBuildModuleId } from "@remix-run/dev"; | ||
``` | ||
|
||
Creating the Vite server in middleware mode: | ||
|
||
```diff | ||
const vite = | ||
process.env.NODE_ENV === "production" | ||
? undefined | ||
- : await unstable_createViteServer(); | ||
+ : await import("vite").then(({ createServer }) => | ||
+ createServer({ | ||
+ server: { | ||
+ middlewareMode: true, | ||
+ }, | ||
+ }) | ||
+ ); | ||
``` | ||
|
||
Loading the Vite server build in the request handler: | ||
|
||
```diff | ||
app.all( | ||
"*", | ||
createRequestHandler({ | ||
build: vite | ||
- ? () => unstable_loadViteServerBuild(vite) | ||
+ ? () => vite.ssrLoadModule(unstable_viteServerBuildModuleId) | ||
: await import("./build/server/index.js"), | ||
}) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
// This file allows us to dynamically require the plugin so non-Vite consumers | ||
// don't need to have Vite installed as a peer dependency. Only types should | ||
// be imported at the top level. | ||
import type { ViteDevServer } from "vite"; | ||
|
||
import type { RemixVitePlugin } from "./plugin"; | ||
import { id } from "./vmod"; | ||
import { serverEntryId } from "./server-entry-id"; | ||
|
||
export const unstable_vitePlugin: RemixVitePlugin = (...args) => { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports | ||
let { remixVitePlugin } = require("./plugin") as typeof import("./plugin"); | ||
return remixVitePlugin(...args); | ||
}; | ||
|
||
export const unstable_createViteServer = async () => { | ||
let vite = await import("vite"); | ||
return vite.createServer({ | ||
server: { | ||
middlewareMode: true, | ||
}, | ||
}); | ||
}; | ||
|
||
export const unstable_loadViteServerBuild = async (vite: ViteDevServer) => { | ||
return vite.ssrLoadModule(id("server-entry")); | ||
}; | ||
// We rename this export because from a consumer's perspective this is the | ||
// "server build" since they also provide their own server entry | ||
export const unstable_viteServerBuildModuleId = serverEntryId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// This file allows us to export the module ID without forcing non-Vite | ||
// consumers to inadvertently import the Vite plugin and all of its dependencies | ||
import * as VirtualModule from "./vmod"; | ||
|
||
export const serverEntryId = VirtualModule.id("server-entry"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters