-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable vercel image optimization #8667
feat: enable vercel image optimization #8667
Conversation
🦋 Changeset detectedLatest commit: 885ba69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
If the other maintainers agree to add this we would need to document it in https://github.com/sveltejs/kit/blob/master/documentation/docs/25-build-and-deploy/90-adapter-vercel.md |
Thanks for the PR! The Can you describe how you'd use this in practice? If I understand correctly this would allow you do have images like this... <img alt="..." src="/_vercel/image?url=/images/potato.jpg"> ...but that wouldn't work in development. It feels like we might need a more integrated solution (which is part of a larger conversation around adapters being able to augment the dev server environment). |
Correct this is the usage. The pull request is only giving the ability to set the options in the build docs. Other than that it does nothing unless further functionality is implemented by the user. That said, I don't think that it needs to wait for a full solution in order to implement. I'd argue to allow it so that other people can build an image component, or custom pre-render function would solve for it in production. |
I definitely understand that sentiment, but there's a fine line between shipping incremental improvements in the spirit of 'don't let the perfect be the enemy of the good' and narrowing the eventual solution space. There's always a cost to adding new API, so it's important not to add something that you plan to make obsolete. By adding this feature we're essentially saying 'this is how images should be optimised', but a) it creates a form of vendor lock-in (even if I work at Vercel, I don't want to make it harder for people to move between platforms), and b) there's a usage cost attached to runtime image optimisation, whereas optimising images at build time (with https://www.npmjs.com/package/vite-imagetools, for example) is free. So for me, until we're able to offer an |
I make it work in dev by using an image host environment variable. In dev the page serves the normal images from their normal paths, and in production it uses the Vite-imagetools is great for static assets at build-time, but it doesn't allow for optimization of user-submitted images because they won't exist to be imported and optimized. In that case your option is already basically go pay for cloudinary anyways, so I don't think the usage cost is a big deal. I think it's fine for a platform specific adapter to enable platform-specific features, and that's already being done with KV and durable objects on the cloudflare adapter, but I do think that the pricing and limitations are worth calling out in any documentation referencing the platform-specific features. |
The main reason for wanting this feature is because I find it very rare for the image source files to live in the project. They often have a CMS component and are served remotely. At the end of the day we are going to be paying someone to serve nextgen images and not statically creating all of them. In this case keeping it closer to the code source by it being a vercel product is an advantage for me in simplicity and accounting. The pricing seems fair. If this option is not added to adapter package then you aren't even giving the company who is supporting the project the ability to gain more business for fear of nepotism and/or we will have to maintain our own forked adapters. TLDR: Images coming from CMS can't take advantage of vitetools in a non-static environment and vercel has a viable option for quickly offloading that task and keeping image implementation within the project scope |
Here's a workaround in the meantime, pending a more complete decision: // scripts/vercel-images.js
import fs from 'node:fs';
const file = '.vercel/output/config.json';
const config = {
...JSON.parse(fs.readFileSync(file, 'utf-8')),
images: {
// config goes here
}
};
fs.writeFileSync(file, JSON.stringify(config, null, 2)); // package.json
{
// ...
"scripts": {
// ...
"build": "vite build && node scripts/vercel-images"
}
} |
When will this land? Are there anything that I can help? I need this desperately. |
Check this repo for implementation |
Thank you for this. However, I'm going to go ahead and close it for the reasons Rich mentioned above. We do recognize this is important and took a stab at implementing it in #9787. That's been on hold after we using it led to further discussion amongst the team. We've been a bit distracted building Svelte 5 since then. I know it's hard not to have any built-in solutions yet, but we've always erred on the side of getting it right vs getting it soon |
I personally think this PR makes sense to add now and we can follow up with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will still need some further discussion with the other maintainers as to whether we want to go in this direction, but this PR is well done and looks good to me
First PR, please excuse any mistakes I have made but I have done my best to follow the contribution guidelines
attempt to close #8561.
Exposes the necessary config to enable Vercel image optimization. Currently, with no accompanying component it won't be as convenient as something like Next/image, but is still much better than having no option at all. I'm currently running with these changes using pnpm patch on one of my current projects and I find it incredibly useful.
I wrapped the images config object in a platform object. My thought process was that it's not really a config option for the adapter itself, but rather a config option for the platform the build output will be deployed to. It also leaves room to enable future vercel features without adding a bunch of new root-level config-options to the adapter, they can just become part of the platform object.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.