Eleventy Plugin Local Responsive Images
Eleventy plugin for resizing and optimizing local images, and rewriting img
tags to make use of the resized and optimized images (collectively, "responsive images"). Works by finding local images in img
tags that aren't already wrapped in a picture
tag and, where applicable, resizing, optimizing, and converting to webp
. Can take a glob of additional images to watch and optimize as well. Additional images will not be resized or have a WebP version made.
Supported image types:
- png - optimize/resize/webp
- jpg - optimize/resize/webp
- gif - optimize/resize/webp/mp4
- svg - optimize
Usage
const pluginLocalRespimg = require('eleventy-plugin-local-respimg');
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginLocalRespimg, {
folders: {
source: 'src',
output: 'public',
},
images: {
resize: {
min: 250,
max: 1500,
step: 150,
},
hoistClasses: false,
gifToVideo: false,
sizes: '100vw',
lazy: true,
additional: [
'images/icons/**/*',
],
watch: {
src: 'images/**/*',
},
pngquant: {
},
mozjpeg: {
},
svgo: {
},
gifresize: {
},
webp: {
},
gifwebp: {
},
},
});
};
Troubleshooting
SVGs
SVGs are required to have <?xml version="1.0" encoding="utf-8"?>
at the top of the file in order to have their MIME type properly read and for SVGs to work.