Home / File/ image-config.ts — astro Source File

image-config.ts — astro Source File

Architecture documentation for image-config.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

File typescript CoreAstro RoutingSystem 2 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f4f77a1d_ebf2_80a3_83fc_469f07314c0b["image-config.ts"]
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  f4f77a1d_ebf2_80a3_83fc_469f07314c0b --> f16d8c76_2866_6150_bd14_0347b59abfe9
  3b10c06c_a805_be1f_3a3d_1f00ea858ef5["config"]
  f4f77a1d_ebf2_80a3_83fc_469f07314c0b --> 3b10c06c_a805_be1f_3a3d_1f00ea858ef5
  style f4f77a1d_ebf2_80a3_83fc_469f07314c0b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { AstroConfig, AstroIntegrationLogger, HookParameters } from 'astro';
import { passthroughImageService, sharpImageService } from 'astro/config';

export type ImageService =
	| 'passthrough'
	| 'cloudflare'
	| 'cloudflare-binding'
	| 'compile'
	| 'custom';

export function setImageConfig(
	service: ImageService,
	config: AstroConfig['image'],
	command: HookParameters<'astro:config:setup'>['command'],
	logger: AstroIntegrationLogger,
) {
	switch (service) {
		case 'passthrough':
			return { ...config, service: passthroughImageService() };

		case 'cloudflare':
			return {
				...config,
				service:
					command === 'dev'
						? sharpImageService()
						: { entrypoint: '@astrojs/cloudflare/image-service' },
			};
		case 'cloudflare-binding':
			return {
				...config,
				endpoint: {
					entrypoint: '@astrojs/cloudflare/image-transform-endpoint',
				},
			};

		case 'compile':
			return {
				...config,
				service: sharpImageService(),
				endpoint: {
					entrypoint: command === 'dev' ? undefined : '@astrojs/cloudflare/image-endpoint',
				},
			};

		case 'custom':
			return { ...config };

		default:
			if (config.service.entrypoint === 'astro/assets/services/sharp') {
				logger.warn(
					`The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'passthrough' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`,
				);
				return { ...config, service: passthroughImageService() };
			}
			return { ...config };
	}
}

Domain

Subdomains

Functions

Types

Dependencies

  • astro
  • config

Frequently Asked Questions

What does image-config.ts do?
image-config.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in image-config.ts?
image-config.ts defines 1 function(s): setImageConfig.
What does image-config.ts depend on?
image-config.ts imports 2 module(s): astro, config.
Where is image-config.ts in the architecture?
image-config.ts is located at packages/integrations/cloudflare/src/utils/image-config.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/cloudflare/src/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free