Skip to content

Commit

Permalink
vite: typesafe server build
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed Feb 21, 2024
1 parent dc5cdb7 commit a7d62c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/remix-dev/index.ts
Expand Up @@ -12,4 +12,8 @@ export type {
ServerBundlesFunction,
VitePluginConfig,
} from "./vite";
export { vitePlugin, cloudflareDevProxyVitePlugin } from "./vite";
export {
vitePlugin,
cloudflareDevProxyVitePlugin,
getServerBuild,
} from "./vite";
21 changes: 21 additions & 0 deletions packages/remix-dev/vite/get-server-build.ts
@@ -0,0 +1,21 @@
import type { ViteDevServer } from "vite";
import type { ServerBuild } from "@remix-run/server-runtime";

const devServerBuild = "virtual:remix/server-build";

export async function getServerBuild(
path: string,
viteDevServer?: ViteDevServer
): Promise<ServerBuild> {
if (viteDevServer) {
return viteDevServer.ssrLoadModule(devServerBuild) as Promise<ServerBuild>;
}
try {
return import(path);
} catch (error) {
console.error(
`Could not find server build at '${path}'. Did you forget to run 'remix vite:build' first?`
);
throw error;
}
}
1 change: 1 addition & 0 deletions packages/remix-dev/vite/index.ts
Expand Up @@ -15,4 +15,5 @@ export const vitePlugin: RemixVitePlugin = (...args) => {
return remixVitePlugin(...args);
};

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

0 comments on commit a7d62c4

Please sign in to comment.