Respect custom image services for Cloudflare build-time generation (compile + custom)#17099
Respect custom image services for Cloudflare build-time generation (compile + custom)#17099adamchal wants to merge 6 commits into
compile + custom)#17099Conversation
🦋 Changeset detectedLatest commit: 1882dcb The changes in this PR will be included in the next version bump. This PR includes changesets to release 40 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
|
We have the |
matthewp
left a comment
There was a problem hiding this comment.
Want to understand why 'custom' doesn't work for them, would prefer to keep the image config simple if possible.
|
From docs and true in index.ts#L470. I considered making the change to |
|
@matthewp you were right: there isn’t really a good reason to prevent The actual caveat with I updated the PR to let |
|
@adamchal great! Code looks good. Yeah we do need a docs update just because the signature changed. |
|
Drafted a docs PR withastro/docs#14095. Thanks for the guidance @matthewp! |
|
Haven't forgotten about this one. Hope to get it in soon. |
|
This is ready, pending the changeset change. |
|
Also closes #16035 |
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks, LGTM docs-wise!
I also added #16035 to the "Development" section. This may be due to the non-capitalization of "closes" in Matthew's post, but it was not added automatically.
a59786d to
09cd4c1
Compare
pnpm v11 skips the current-platform optional native binary (@img/sharp-win32-x64) on the Windows runner, so sharp fails to load during build-time image generation. Force-install the @img/sharp-* binaries for all CI OS/CPU targets via supportedArchitectures.
09cd4c1 to
1882dcb
Compare
Changes
image.servicewhen the Cloudflare adapter is usingimageService: 'compile', so customgetURL()andgetHTMLAttributes()hooks are used while prerendering markup in workerd.transform()hooks are used for generated image assets.imageService: 'custom'to also generate optimized image assets at build time, mirroringcompile. It runs the configuredimage.service(or Astro's default Sharp service when none is set) during the Node-side generation pass, while continuing to use the configured service for runtime image handling.imageServiceimage.service'compile''compile'transform()hooks were skipped.transform()hook during image generation.'custom'customtradeoff.'custom''cloudflare' | 'cloudflare-binding' | 'passthrough'Testing
imageService: 'compile'andimageService: 'custom'across three service configurations: no user service (Astro's default Sharp service), a Sharp-free custom service, and a Sharp-backed custom service. Each cell asserts:_astro/*.webpassets are generated at build time (real WEBP bytes, or the customtransform()marker for the Sharp-free user service);getHTMLAttributes()markup is preserved;compilestays Sharp-free (Sharp runs only on the Node side);customreflects its configured runtime service — clean for a Sharp-free user service, but dragging Sharp in for both a Sharp-backed user service and the no-image.servicedefault.Docs
'compile'mode “uses image.service, if defined otherwise a combination of internal dependencies to transform images locally at build time for prerendered routes.” And it could also mention that'custom'will do the same thing during build time. But, it may not be necessary—I feel like this is what I expected to be the case. Happy to draft awithastro/docsPR.imageServicedocs for custom image service support docs#14095Related PRs
{ build: 'cloudflare-binding' }mode so the Cloudflare Images binding transforms prerendered images during the build (writing optimized bytes directly, falling back to Sharp); this PR keeps local image-service generation paths working with custom image services and brings build-time generation tocustommode. The behaviors should compose:compileandcustomrespect custom local image services, while the opt-incloudflare-bindingbuild mode uses the Images binding.Closes #16201