Skip to content
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

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-clocks-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': minor
---

feat: expose vercel image optimization config in adapter config
24 changes: 24 additions & 0 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ type Options = {
edge?: boolean;
external?: string[];
split?: boolean;
platform?: VercelConfig;
};

type ImageFormat = 'image/avif' | 'image/webp';

type RemotePattern = {
protocol?: 'http' | 'https';
hostname: string;
port?: string;
pathname?: string;
};

type ImagesConfig = {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
sizes: number[];
domains: string[];
remotePatterns?: RemotePattern[];
minimumCacheTTL?: number; // seconds
formats?: ImageFormat[];
dangerouslyAllowSVG?: boolean;
contentSecurityPolicy?: string;
};

type VercelConfig = {
images: ImagesConfig;
};

export default function plugin(options?: Options): Adapter;
12 changes: 10 additions & 2 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { nodeFileTrace } from '@vercel/nft';
import esbuild from 'esbuild';

/** @type {import('.').default} **/
const plugin = function ({ external = [], edge, split } = {}) {
const plugin = function ({ external = [], edge, split, platform = {} } = {}) {
return {
name: '@sveltejs/adapter-vercel',

Expand Down Expand Up @@ -134,6 +134,10 @@ const plugin = function ({ external = [], edge, split } = {}) {
await generate_function('render', '/.*', builder.generateManifest);
}

if (platform && platform?.images) {
config.images = platform.images;
}

builder.log.minor('Copying assets...');

builder.writeClient(dirs.static);
Expand Down Expand Up @@ -182,6 +186,9 @@ function static_vercel_config(builder) {
/** @type {Record<string, { path: string }>} */
const overrides = {};

/** @type {import('./index').ImagesConfig} */
const images = undefined;

for (const [src, redirect] of builder.prerendered.redirects) {
prerendered_redirects.push({
src,
Expand Down Expand Up @@ -219,7 +226,8 @@ function static_vercel_config(builder) {
handle: 'filesystem'
}
],
overrides
overrides,
images
};
}

Expand Down