Skip to content

Options

ts
distCompress(options?: AstroDistCompressOptions)

AstroDistCompressOptions

OptionTypeDefaultDescription
rulesCompressRule[]defaultRulesOrdered conversion rules. First match wins.
fallbackFallbackConfig | false{ enabled: true, format: "webp" }Auto-adds a fallback output to every rule. See Fallback images.
rewriteHtmlbooleantrueRewrite <img> into <picture> in the build output's HTML. See HTML rewriting.
removeOriginalbooleanfalseDelete original files once a fallback output exists. See Removing originals.
extensionsstring[]["png", "jpg", "jpeg"]File extensions (without the dot) to scan for in the build output.
excludestring[][]Glob patterns, relative to the output root, to skip entirely.
concurrencynumber4Number of images processed in parallel.
loggerbooleantrueLog progress and a bytes-saved summary via Astro's integration logger.
dryRunbooleanfalsePreview a run without touching the filesystem. See Dry run, errors & reporting.
onError"skip" | "throw""skip"What to do when converting a single image fails. See Dry run, errors & reporting.
reportstring | falsefalseWrite a JSON summary of the run to this path. See Dry run, errors & reporting.

CompressRule

FieldTypeDescription
namestring?Label used only in logs.
match(ctx: ImageContext) => booleanDecides whether the rule applies to a given image.
outputsOutputTarget[]Formats to produce for matched images.
removeOriginalboolean?Overrides the global removeOriginal for this rule.

OutputTarget

FieldTypeDescription
formatImageFormatTarget format: "avif" | "webp" | "png" | "jpeg" | "jpg" | "gif" | "tiff".
optionsRecord<string, unknown>?Passed straight through to sharp's .toFormat(format, options).
fallbackboolean?Marks this output as the one used for the final <img src>.
sameFormatSuffixstring?Suffix used when the target format equals the source format, to avoid overwriting it. Default: "-compressed".
widthsnumber[]?Generate one width-resized variant per entry, wired up as a srcset. Widths larger than the source are dropped (no upscaling). See Responsive images.
sizesstring?sizes attribute emitted on the corresponding <source>/<img> when widths produces more than one variant.

FallbackConfig

FieldTypeDefaultDescription
enabledboolean?trueWhether to auto-add the fallback format to every rule.
formatImageFormat?"webp"Format to auto-add.
optionsRecord<string, unknown>?{ quality: 80 }Encode options for the auto-added output.

ImageContext

Passed to every rule's match function — see Rules for the full shape and field descriptions.