The best way to control Claude Code, Codex and more from any computer or phone

main
ts 46 lines 1.22 KB
Raw
1 import { createPlugin } from "../factory.ts";
2
3 export const CLOUDFLARE_BUILT_IN_MODULES = [
4 "cloudflare:durable-objects",
5 "cloudflare:email",
6 "cloudflare:node",
7 "cloudflare:sockets",
8 "cloudflare:workers",
9 "cloudflare:workflows",
10 ];
11
12 export const cloudflareExternalsPlugin = createPlugin("cloudflare-externals", () => ({
13 rolldown: {
14 resolveId: {
15 filter: { id: /^cloudflare:/ },
16 handler(id) {
17 if (!CLOUDFLARE_BUILT_IN_MODULES.includes(id)) {
18 return;
19 }
20
21 return {
22 id,
23 external: true,
24 };
25 },
26 },
27 },
28 vite: {
29 enforce: "pre",
30 configEnvironment(name) {
31 if (name === "client") {
32 // Some frameworks allow users to mix client and server code in the same file and then extract the server code.
33 // As the dependency optimization may happen before the server code is extracted, we should exclude Cloudflare built-ins from client optimization.
34 return { optimizeDeps: { exclude: CLOUDFLARE_BUILT_IN_MODULES } };
35 }
36 return {
37 resolve: {
38 builtins: CLOUDFLARE_BUILT_IN_MODULES,
39 },
40 optimizeDeps: {
41 exclude: CLOUDFLARE_BUILT_IN_MODULES,
42 },
43 };
44 },
45 },
46 }));