Eleventy Plugin Baseline

A magic carpet ride

Table of Contents

Image Transform

Use Eleventy’s HTML Transform (eleventyImageTransformPlugin) to rewrite your <img> (and <picture>) into responsive markup with generated assets and caching.

This guide shows you how to wire the `eleventyImageTransformPlugin` plugin from `eleventy-img` alongside Baseline. Baseline does not ship this transform by default.

Prerequisites

  • Eleventy 3.x and @11ty/eleventy-img installed.
  • site.url set to your origin (no subpath).
  • Images referenced in your content or templates (local or remote).

Steps

  1. @11ty/eleventy-img is already required by Baseline; you can reinstall to ensure it’s present:

    npm install @11ty/eleventy-img
    npm install @11ty/eleventy-img
  2. Enable the HTML transform in eleventy.config.js.

    import baseline, { config as baselineConfig } from './_baseline/eleventy.config.js';
    
    import path from 'node:path';
    import { eleventyImageTransformPlugin } from '@11ty/eleventy-img';
    
    /** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
    export default async function (eleventyConfig) {
    	eleventyConfig.addPlugin(baseline());
    	eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
    		urlPath: '/media/',
    		outputDir: './dist/media/',
    		formats: ['avif', 'webp', 'jpeg'],
    		widths: [320, 640, 960, 1280],
    		filenameFormat(id, src, width, format) {
    			const extension = path.extname(src);
    			const name = path.basename(src, extension);
    			return `${name}-${width}w.${format}`;
    		}
    	});
    }
    
    export const config = baselineConfig;
  3. Write plain <img> in content.

    The transform rewrites <img> to <picture> (with sources) at build time. Keep alt on every image. Example in Markdown:

    ## Image Transform Plugin
    
    <figure>
      <img src="/media/mountains.jpg" alt="Mountains at sunset" loading="lazy">
      <figcaption>
        Example image rendered responsively with the Eleventy Image Transform plugin.
      </figcaption>
    </figure>
  4. Handle remote images and caching.

    Remote src values are fetched and cached on disk. Ensure the build environment can reach them. Cache defaults come from the plugin; adjust if you need a different cache dir.

  5. Build and verify.

    • Dev: npx rimraf dist/ && npm run dev
    • Build: npx rimraf dist/ && npm run build
    • Inspect rendered HTML: you should see <picture> with multiple <source> tags and <img> including width/height.
    • Check generated files under dist/media/.

Notes

  • Keep site.url origin-only; if you deploy under a subpath, set pathPrefix separately.
  • formats order matters; the first format is preferred by the browser.
  • Use sizes (default from plugin) if you need custom responsive behavior; set sizes in the plugin options.
  • For advanced options (cache, returnType/htmlOptions, remote fetch), see the Eleventy Image docs.