feat(cloudflare): refactor image service config#15662
feat(cloudflare): refactor image service config#15662OliverSpeir wants to merge 8 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: e6f8ab6 The changes in this PR will be included in the next version bump. 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 |
Ai file-by-file breakdown1. Rewrite
|
|
@OliverSpeir can we get this shipped? 👀 |
|
|
||
| - `cloudflare-binding` (default) — uses the Cloudflare Images binding (`IMAGES`) for transforms | ||
| - `cloudflare` — uses Cloudflare's CDN (`cdn-cgi/image`) for URL-based transforms | ||
| - `compile` — Sharp at build time and in dev, passthrough at runtime (pre-optimized assets served as-is) |
There was a problem hiding this comment.
| - `compile` — Sharp at build time and in dev, passthrough at runtime (pre-optimized assets served as-is) | |
| - `prerender-sharp` — Sharp at build time and in dev, passthrough at runtime (pre-optimized assets served as-is) |
Idea to make this understandable. Users might not understand compile, why not build. I suggest prerender-sharp. Let me explain. prerender because it only applies to pages with prerender = true, which is familar to Astro users. sharp because we should explicitly say what local solution we use, as there could be other.
Changes
Normalises all
imageServiceconfig into a{ buildService, devService, runtimeService }triple, makes custom Node-only image services work with compile, adds a Vite dev middleware that uses jiti to dynamically import the image service entrypoint in Node, so custom TypeScript services work in devConfig shapes
Available presets:
cloudflare-binding(default) |cloudflare|compile|passthrough|custom(deprecated)What each preset resolves to
cloudflare-binding(default)image-service-workerdimage-service-workerdimage-service-workerdfalsecloudflareimage-service(cdn-cgi)sharpimage-service(cdn-cgi)falsecompileimage-service-workerd(stub)sharppassthroughtruepassthroughnoopnoopnoopfalsecustom(deprecated)image-service-workerd(stub)sharpconfig.image.servicetrueWhen
transformsAtBuildis true, images are transformed at build time in Node (via Sharp or a custom service), and the deployed Worker just serves transformed static assets.Other api facets
imageService: 'sharp'throws with guidance to use'compile'insteadimageService: 'custom'deprecated, eventually will be copy paste from their astro config.images to the config.adapterconfig.image.serviceinconfig:setupis automatically picked up by thecompilepreset (captured inconfig:done) (this means integrations like Chris's sweetcorn dithering tool will work with compile)Testing
added tests
Docs
Haven't written yet, will need to though, ideally get feedback on if this is the right api before writing them