Skip to content

Commit 1ca842d

Browse files
committed
vite: typesafe server build
1 parent dc5cdb7 commit 1ca842d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/remix-dev/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ export type {
1212
ServerBundlesFunction,
1313
VitePluginConfig,
1414
} from "./vite";
15-
export { vitePlugin, cloudflareDevProxyVitePlugin } from "./vite";
15+
export {
16+
vitePlugin,
17+
cloudflareDevProxyVitePlugin,
18+
getServerBuild,
19+
} from "./vite";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { ViteDevServer } from "vite";
2+
import type { ServerBuild } from "@remix-run/server-runtime";
3+
4+
const devServerBuild = "virtual:remix/server-build";
5+
6+
export async function getServerBuild(
7+
path: string,
8+
viteDevServer?: ViteDevServer
9+
): Promise<ServerBuild> {
10+
if (viteDevServer) {
11+
return viteDevServer.ssrLoadModule(devServerBuild) as Promise<ServerBuild>;
12+
}
13+
try {
14+
return import(path);
15+
} catch (error) {
16+
console.error(
17+
`Could not find server build at '${path}'. Did you forget to run 'remix vite:build' first?`
18+
);
19+
throw error;
20+
}
21+
}

packages/remix-dev/vite/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file allows us to dynamically require the plugin so non-Vite consumers
22
// don't need to have Vite installed as a peer dependency. Only types should
33
// be imported at the top level, or code that doesn't import Vite.
4+
45
import type { RemixVitePlugin } from "./plugin";
56
export type {
67
BuildManifest,
@@ -15,4 +16,5 @@ export const vitePlugin: RemixVitePlugin = (...args) => {
1516
return remixVitePlugin(...args);
1617
};
1718

19+
export { getServerBuild } from "./get-server-build";
1820
export { cloudflareDevProxyVitePlugin } from "./cloudflare-proxy-plugin";

0 commit comments

Comments
 (0)