This MRE tries to use our own Astro image.service.transform() while
statically generating pages through @astrojs/cloudflare's workerd prerenderer.
Astro v6.4.7
@astrojs/cloudflare v13.7.0
Output static (with a server endpoint, so the workerd prerenderer runs)
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()addsdata-image-service="custom".transform()prependsCUSTOM_TRANSFORM_RANto generated files and logs the same marker.
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; collectStaticImagesswitches build-time generation toastro/assets/services/sharp, so the customtransform()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().
npm install
npm run buildThen inspect the output:
grep -o '<img[^>]*>' dist/client/index.html
head -c 24 dist/client/_astro/*.webp | xxdThe <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.
The custom service should be respected end-to-end under compile:
- the
<img>carriesdata-image-service="custom", and - generated files begin with
CUSTOM_TRANSFORM_RAN, proving the customtransform()ran during SSG.
- 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"andimageService: { 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.