A variant is a named override set that lets one composition file produce multiple distinct outputs. Instead of maintaining separate files for your Open Graph image, Twitter card, and square thumbnail, you define aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/andresilva-cc/grafex/llms.txt
Use this file to discover all available pages before exploring further.
variants map in config and let Grafex render them all in a single pass. Each variant inherits every field from the base config and can replace any of them — dimensions, format, props, CSS, fonts, or HTML attributes.
Defining variants
Add avariants key to your CompositionConfig. Each entry is a variant name mapped to a VariantConfig object. A VariantConfig accepts the same fields as CompositionConfig minus the variants key itself.
og variant has an empty config object — it inherits the base 1200×630 dimensions exactly. The twitter variant overrides only the height. The square variant changes both dimensions and also passes a layout prop to the component so it can adjust its layout for the square aspect ratio.
Merge rules
Understanding how variant fields are merged with the base config prevents surprises:Scalar fields
Fields like
width, height, scale, format, and quality replace the base value when set in the variant. If not set in the variant, the base config value is used.props
Shallow-merged: variant
props are applied first, then CLI/API props override individual keys on top. Neither replaces the other wholesale.Array fields (fonts, css)
Replaced entirely — the variant’s array is used as-is instead of the base config’s array. There is no concatenation.
htmlAttributes
Spread over base: variant attributes are shallow-merged on top of the base
htmlAttributes object, so you can override one key without losing the others.Exporting variants from the CLI
When a composition defines variants,grafex export renders all of them by default and names each output file after the variant key.
When you pass
-o with a directory path (trailing slash or an existing directory), Grafex writes <variant>.<format> files inside it. When you pass a file path, you must also pass --variant to select which variant to render.Rendering variants via the Node.js API
Userender to produce a single named variant:
renderAll to render every variant in one call. It returns a Map<string, RenderResult> keyed by variant name:
Variants with htmlAttributes
Variants can override individual HTML attributes without replacing the whole set. In the example below, both variants inheritlang: 'en' from the base config, but each sets a different data-theme:
default variant renders with <html lang="en" data-theme="light">. The dark variant renders with <html lang="en" data-theme="dark"> — lang is inherited, only data-theme changes.