Skip to content

Commit 9d8bd81

Browse files
committed
enable images local mode by default
1 parent 8b925c9 commit 9d8bd81

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

.changeset/wild-paws-occur.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"@cloudflare/vite-plugin": patch
33
---
44

5-
fix: add experimental local mode support for image bindings
5+
fix: enable image local mode by default with the images binding
66

7-
You can now enable experimental local image binding support in the Vite plugin by setting the `experimental.imagesLocalMode` option to `true`. This provides the same functionality as running `wrangler dev --experimental-images-local-mode`.
7+
Previously, image local mode was not enabled by default when using the images binding and would use a remote setup even when the remote option was not enabled. This enables local mode by default for image bindings.

packages/vite-plugin-cloudflare/playground/bindings/__tests__/worker.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ test("kv_namspaces support", async () => {
66
expect(response).toBe("KV binding works");
77
});
88

9-
test("experimental images local mode support", async () => {
10-
const response = await getTextResponse("/images-local-mode");
11-
expect(response).toBe("Local images binding works");
9+
test("images support", async () => {
10+
const response = await getTextResponse("/images");
11+
expect(response).toBe("Images binding works");
1212
});
1313

1414
test("unsafe_hello_world support", async () => {

packages/vite-plugin-cloudflare/playground/bindings/src/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,23 @@ export default {
2020
status: 200,
2121
});
2222
}
23-
case "/images-local-mode": {
23+
case "/images": {
2424
const request = await fetch(image);
2525

2626
if (!request.body) {
2727
return new Response("Failed to fetch image", { status: 500 });
2828
}
2929

30-
try {
31-
await env.IMAGES.input(request.body).output({ format: "image/gif" });
32-
} catch (e) {
33-
if (
34-
e instanceof Error &&
35-
e.message.includes("GIF output is not supported in local mode")
36-
) {
37-
return new Response("Local images binding works", {
38-
status: 200,
39-
});
40-
}
30+
const info = await env.IMAGES.info(request.body);
31+
32+
if (info.format !== "image/png") {
33+
return new Response("Images binding returns an incorrect format", {
34+
status: 500,
35+
});
4136
}
4237

43-
return new Response("Local images binding is not configured properly", {
44-
status: 500,
38+
return new Response("Images binding works", {
39+
status: 200,
4540
});
4641
}
4742
case "/ae": {

packages/vite-plugin-cloudflare/playground/bindings/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export default defineConfig({
66
cloudflare({
77
inspectorPort: false,
88
persistState: false,
9-
experimental: { imagesLocalMode: true },
109
}),
1110
],
1211
});

packages/vite-plugin-cloudflare/src/miniflare-options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,7 @@ export async function getDevMiniflareOptions(config: {
421421
},
422422
resolvedPluginConfig.cloudflareEnv,
423423
{
424-
imagesLocalMode:
425-
resolvedPluginConfig.experimental.imagesLocalMode,
424+
imagesLocalMode: true,
426425
remoteProxyConnectionString:
427426
remoteProxySessionData?.session
428427
?.remoteProxyConnectionString,

packages/vite-plugin-cloudflare/src/plugin-config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ interface Experimental {
3737
headersAndRedirectsDevModeSupport?: boolean;
3838
/** Experimental support for remote bindings (where bindings configured with `remote: true` access remote resources). */
3939
remoteBindings?: boolean;
40-
/** Experimental support for local images bindings */
41-
imagesLocalMode?: boolean;
4240
}
4341

4442
export interface PluginConfig extends EntryWorkerConfig {

0 commit comments

Comments
 (0)