Closed zachleat closed 1 year ago
const { eleventyImagePlugin } = require("@11ty/eleventy-img"); module.exports = function(eleventyConfig) { // Add as a global WebC component eleventyConfig.addPlugin(pluginWebc, { components: [ "./_components/**/*.webc", "npm:@11ty/eleventy-img/*.webc", ] }); // Set global defaults in configuration eleventyConfig.addPlugin(eleventyImagePlugin, { // full options list on https://www.11ty.dev/docs/plugins/image/#usage formats: ["avif", "webp", "jpeg"], urlPath: "/img/built/", // outputDir is resolved automatically via urlPath 👀 (but you can override it) defaultAttributes: { loading: "lazy", decoding: "async" } }); };
<img webc:is="eleventy-image" src="possum.png" alt="…">
Specify widths:
<img webc:is="eleventy-image" src="possum.png" alt="…" width="100, 200"> <img webc:is="eleventy-image" src="possum.png" alt="…" :width="[100, 200]">
Specify formats (overriding defaults set via the configuration above):
<img webc:is="eleventy-image" src="possum.png" alt="…" formats="avif, png"> <img webc:is="eleventy-image" src="possum.png" alt="…" :formats="['avif', 'png']">
Change the url path or output dir (overriding defaults set via the configuration above):
<img webc:is="eleventy-image" src="possum.png" alt="…" url-path="/some-dir/" output-dir="_site/some-dir/">
Usage:
Eleventy Configuration
Example WebC usage
Specify widths:
Specify formats (overriding defaults set via the configuration above):
Change the url path or output dir (overriding defaults set via the configuration above):