-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
51 lines (47 loc) · 1.84 KB
/
Copy pathvite.config.ts
File metadata and controls
51 lines (47 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import path from "node:path";
import { defineConfig, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
import { cloudflare } from "@cloudflare/vite-plugin";
import tailwindcss from "@tailwindcss/vite";
// Plugin to stub out server-only modules in the browser
function stubServerModules(): Plugin {
return {
name: "stub-server-modules",
enforce: "pre",
resolveId(id, importer, options) {
// Stub gateway for all browser code (not SSR)
if (id === "@ai-sdk/gateway" && !options.ssr) {
return "\0virtual:@ai-sdk/gateway";
}
},
load(id) {
if (id === "\0virtual:@ai-sdk/gateway") {
// Provide stub exports for all gateway exports (not used in browser)
return `
export const gateway = null;
export const createGateway = () => { throw new Error('Gateway is not available in browser'); };
export const createGatewayProvider = () => { throw new Error('Gateway is not available in browser'); };
// Stub error classes
class GatewayError extends Error {}
export class GatewayAuthenticationError extends GatewayError {}
export class GatewayInvalidRequestError extends GatewayError {}
export class GatewayRateLimitError extends GatewayError {}
export class GatewayModelNotFoundError extends GatewayError {}
export class GatewayInternalServerError extends GatewayError {}
export class GatewayResponseError extends GatewayError {}
// Stub helper functions
export const asGatewayError = (error) => error;
export const wrapGatewayError = (error) => error;
`;
}
}
};
}
export default defineConfig({
plugins: [cloudflare(), react(), tailwindcss(), stubServerModules()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src")
}
}
});