@@ -101,6 +101,23 @@ export type Options = {
101101 */
102102 sessionKVBindingName ?: string ;
103103
104+ /**
105+ * When configured as `cloudflare-binding`, the Cloudflare Images binding will be used to transform images:
106+ * - https://developers.cloudflare.com/images/transform-images/bindings/
107+ *
108+ * By default, this will use the "IMAGES" binding name, but this can be customised in your `wrangler.json`:
109+ *
110+ * ```json
111+ * {
112+ * "images": {
113+ * "binding": "IMAGES" // <-- this should match `imagesBindingName`
114+ * }
115+ * }
116+ * ```
117+ *
118+ */
119+ imagesBindingName ?: string ;
120+
104121 /**
105122 * This configuration option allows you to specify a custom entryPoint for your Cloudflare Worker.
106123 * The entry point is the file that will be executed when your Worker is invoked.
@@ -165,6 +182,17 @@ export default function createIntegration(args?: Options): AstroIntegration {
165182 } ) => {
166183 let session = config . session ;
167184
185+ if ( args ?. imageService === 'cloudflare-binding' ) {
186+ const bindingName = args ?. imagesBindingName ?? 'IMAGES' ;
187+
188+ logger . info (
189+ `Enabling image processing with Cloudflare Images for production with the "${ bindingName } " Images binding.` ,
190+ ) ;
191+ logger . info (
192+ `If you see the error "Invalid binding \`${ bindingName } \`" in your build output, you need to add the binding to your wrangler config file.` ,
193+ ) ;
194+ }
195+
168196 if ( ! session ?. driver ) {
169197 logger . info (
170198 `Enabling sessions with Cloudflare KV with the "${ SESSION_KV_BINDING_NAME } " KV binding.` ,
@@ -356,7 +384,12 @@ export default function createIntegration(args?: Options): AstroIntegration {
356384 vite . define = {
357385 'process.env' : 'process.env' ,
358386 // Allows the request handler to know what the binding name is
359- 'globalThis.__ASTRO_SESSION_BINDING_NAME' : JSON . stringify ( SESSION_KV_BINDING_NAME ) ,
387+ 'globalThis.__ASTRO_SESSION_BINDING_NAME' : JSON . stringify (
388+ args ?. sessionKVBindingName ?? 'SESSION' ,
389+ ) ,
390+ 'globalThis.__ASTRO_IMAGES_BINDING_NAME' : JSON . stringify (
391+ args ?. imagesBindingName ?? 'IMAGES' ,
392+ ) ,
360393 ...vite . define ,
361394 } ;
362395 }
0 commit comments