From af635365051990f8bbdd4e101d7d9f95247d3a2e Mon Sep 17 00:00:00 2001 From: Lasse Hellman Date: Mon, 25 Aug 2025 09:19:56 +0200 Subject: [PATCH] Add experimental remoteBindings as cloudflareDev-option. --- README.md | 1 + examples/nitro/nitro.config.ts | 7 +++++-- examples/nuxt/nuxt.config.ts | 5 +++++ src/index.ts | 9 ++++++++- src/runtime/plugin.dev.ts | 4 ++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 15e03a3..6afed6d 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ You can configure additional options using `cloudflareDev: { }` in `nitro.config - `configPath`: Sets a custom path for `wrangler.toml` file. - `silent`: Hide initial banner. - `environment`: Sets specific environment (useful for multi-environment configurations) +- `remoteBindings`: Enable Wrangler's experimental remoteBindings. ## Development diff --git a/examples/nitro/nitro.config.ts b/examples/nitro/nitro.config.ts index 2345626..90c4a86 100644 --- a/examples/nitro/nitro.config.ts +++ b/examples/nitro/nitro.config.ts @@ -2,5 +2,8 @@ import nitroCloudflareBindings from "nitro-cloudflare-dev"; // https://nitro.unjs.io/config export default defineNitroConfig({ - modules: [nitroCloudflareBindings] -}); + modules: [nitroCloudflareBindings], + // cloudflareDev: { + // remoteBindings: true + // } +}); \ No newline at end of file diff --git a/examples/nuxt/nuxt.config.ts b/examples/nuxt/nuxt.config.ts index c47b08d..07b65f3 100644 --- a/examples/nuxt/nuxt.config.ts +++ b/examples/nuxt/nuxt.config.ts @@ -2,4 +2,9 @@ export default defineNuxtConfig({ modules: ["nitro-cloudflare-dev"], compatibilityDate: "2024-10-10", + // nitro: { + // cloudflareDev: { + // remoteBindings: true, + // }, + // } }); diff --git a/src/index.ts b/src/index.ts index 22a75b3..ee343e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ declare module "nitropack" { environment?: string; persistDir?: string; silent?: boolean; + remoteBindings?: boolean; }; } } @@ -65,7 +66,12 @@ async function nitroModule(nitro: Nitro) { "", `Config path: \`${configPath ? relative(".", configPath) : colorize("yellow", "cannot find `wrangler.json`, `wrangler.jsonc`, or `wrangler.toml`")}\``, `Persist dir: \`${relative(".", persistDir)}\` ${addedToGitIgnore ? colorize("green", "(added to `.gitignore`)") : ""}`, - ].join("\n"), + nitro.options.cloudflareDev?.remoteBindings + ? `Remote bindings: ${colorize("green", "enabled")} (🧪 experimental)` + : undefined, + ] + .filter((row) => row !== undefined) + .join("\n"), ); } @@ -75,6 +81,7 @@ async function nitroModule(nitro: Nitro) { configPath, persistDir, environment: nitro.options.cloudflareDev?.environment, + remoteBindings: nitro.options.cloudflareDev?.remoteBindings, }; // Make sure runtime is transpiled diff --git a/src/runtime/plugin.dev.ts b/src/runtime/plugin.dev.ts index d72d9d7..d0b4f6b 100644 --- a/src/runtime/plugin.dev.ts +++ b/src/runtime/plugin.dev.ts @@ -68,12 +68,16 @@ async function _getPlatformProxy() { configPath: string; persistDir: string; environment?: string; + remoteBindings?: boolean; }; } = useRuntimeConfig(); const proxyOptions: GetPlatformProxyOptions = { configPath: runtimeConfig.wrangler.configPath, persist: { path: runtimeConfig.wrangler.persistDir }, + ...(runtimeConfig.wrangler.remoteBindings && { + experimental: { remoteBindings: true }, + }), }; // TODO: investigate why // https://github.com/pi0/nitro-cloudflare-dev/issues/51