Skip to content

Commit e412647

Browse files
authored
Pass image settings to the optimization module (#299)
1 parent a5a8fb5 commit e412647

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

main.tf

+6-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ module "next_image" {
158158
# device) sizes to the optimizer and by setting the other
159159
# (next_image_device_sizes) to an empty array which prevents the optimizer
160160
# from adding the default device settings
161-
next_image_domains = lookup(local.config_file_images, "domains", [])
162-
next_image_image_sizes = lookup(local.config_file_images, "sizes", [])
163-
next_image_device_sizes = []
161+
next_image_domains = lookup(local.config_file_images, "domains", [])
162+
next_image_image_sizes = lookup(local.config_file_images, "sizes", [])
163+
next_image_device_sizes = []
164+
next_image_formats = lookup(local.config_file_images, "formats", null)
165+
next_image_dangerously_allow_SVG = lookup(local.config_file_images, "dangerouslyAllowSVG", false)
166+
next_image_content_security_policy = lookup(local.config_file_images, "contentSecurityPolicy", null)
164167

165168
source_bucket_id = module.statics_deploy.static_bucket_id
166169

packages/runtime/src/index.ts

+31-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,13 @@ export async function build({
223223
meta = {} as BuildParamsMeta,
224224
}: BuildParamsType): Promise<{
225225
routes: Route[];
226-
images?: { domains: string[]; sizes: number[] };
226+
images?: {
227+
domains: string[];
228+
sizes: number[];
229+
formats?: string[] | undefined;
230+
dangerouslyAllowSVG?: boolean | undefined;
231+
contentSecurityPolicy?: string | undefined;
232+
};
227233
output: Files;
228234
wildcard?: Array<{
229235
domain: string;
@@ -660,11 +666,31 @@ export async function build({
660666
}
661667
if (!Array.isArray(images.sizes)) {
662668
throw new NowBuildError({
663-
code: 'NEXT_IMAGES_DOMAINS',
669+
code: 'NEXT_IMAGES_SIZES',
664670
message:
665671
'image-manifest.json "images.sizes" must be an array. Contact support if this continues to happen.',
666672
});
667673
}
674+
if (
675+
typeof images.dangerouslyAllowSVG !== 'undefined' &&
676+
typeof images.dangerouslyAllowSVG !== 'boolean'
677+
) {
678+
throw new NowBuildError({
679+
code: 'NEXT_IMAGES_DANGEROUSLYALLOWSVG',
680+
message:
681+
'image-manifest.json "images.dangerouslyAllowSVG" must be an boolean. Contact support if this continues to happen.',
682+
});
683+
}
684+
if (
685+
typeof images.contentSecurityPolicy !== 'undefined' &&
686+
typeof images.contentSecurityPolicy !== 'string'
687+
) {
688+
throw new NowBuildError({
689+
code: 'NEXT_IMAGES_CONTENTSECURITYPOLICY',
690+
message:
691+
'image-manifest.json "images.contentSecurityPolicy" must be an string. Contact support if this continues to happen.',
692+
});
693+
}
668694
break;
669695
}
670696
default: {
@@ -2129,6 +2155,9 @@ export async function build({
21292155
? {
21302156
domains: imagesManifest.images.domains,
21312157
sizes: imagesManifest.images.sizes,
2158+
formats: imagesManifest.images.formats,
2159+
dangerouslyAllowSVG: imagesManifest.images.dangerouslyAllowSVG,
2160+
contentSecurityPolicy: imagesManifest.images.contentSecurityPolicy,
21322161
}
21332162
: undefined,
21342163
/*

packages/runtime/src/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ type ImagesManifest = {
522522
loader: LoaderKey;
523523
sizes: number[];
524524
domains: string[];
525+
formats?: string[] | undefined;
526+
minimumCacheTTL?: number | undefined;
527+
dangerouslyAllowSVG?: boolean | undefined;
528+
contentSecurityPolicy?: string | undefined;
525529
};
526530
};
527531

packages/tf-next/src/commands/build.ts

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ interface OutputProps {
5050
images?: {
5151
domains: string[];
5252
sizes: number[];
53+
formats?: string[] | undefined;
54+
dangerouslyAllowSVG?: boolean | undefined;
55+
contentSecurityPolicy?: string | undefined;
5356
};
5457
routes: Route[];
5558
lambdas: Lambdas;

0 commit comments

Comments
 (0)