Skip to content

adamchal/cloudflare-custom-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom transform() during Cloudflare SSG

This MRE tries to use our own Astro image.service.transform() while statically generating pages through @astrojs/cloudflare's workerd prerenderer.

Astro Info

Astro                    v6.4.7
@astrojs/cloudflare      v13.7.0
Output                   static (with a server endpoint, so the workerd prerenderer runs)

Setup

astro.config.ts uses both:

  • adapter: cloudflare({ imageService: "compile" })
  • image.service.entrypoint: "./src/image-service.ts"

The custom local image service extends Astro's baseService and makes two observable changes:

  • getHTMLAttributes() adds data-image-service="custom".
  • transform() prepends CUSTOM_TRANSFORM_RAN to generated files and logs the same marker.

Current behavior

With imageService: "compile", the build output shows neither change:

  • the adapter replaces the configured service with @astrojs/cloudflare/image-service-workerd, so the HTML attribute is missing;
  • collectStaticImages switches build-time generation to astro/assets/services/sharp, so the custom transform() never runs.

"custom" is not an option for this use case. The object form only supports { build: "compile", runtime?: "passthrough" | "cloudflare-binding" }, and imageService: "custom" opts out of compile mode instead of compiling static images with the user-provided transform().

Reproduce

npm install
npm run build

Then inspect the output:

grep -o '<img[^>]*>' dist/client/index.html
head -c 24 dist/client/_astro/*.webp | xxd

The <img> is missing data-image-service="custom", the generated asset starts with RIFF/WEBP instead of CUSTOM_TRANSFORM_RAN, and the marker is not logged during the build.

Expected

The custom service should be respected end-to-end under compile:

  • the <img> carries data-image-service="custom", and
  • generated files begin with CUSTOM_TRANSFORM_RAN, proving the custom transform() ran during SSG.

Notes

  • The server endpoint at src/pages/api.ts (prerender = false) makes the build hybrid so the workerd prerenderer runs for static pages. That is the path the compile image pipeline lives in.
  • For this MRE, imageService: "compile" and imageService: { build: "compile" } hit the same build-time path; the compound form only changes the runtime image service.
  • The marker transform() intentionally produces a non-image file; this repo exists to prove which code path ran, not to render a valid image.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors