Skip to content

Transform method option to put generated image disk cache in .cache folder #285

Open
@zachleat

Description

This works today to store output images into .cache/ and then copy those assets to the output folder post-build:

import fs from "node:fs";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";

export default async function(eleventyConfig) {
	// Image optimization: https://www.11ty.dev/docs/plugins/image/#eleventy-transform
	eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
		outputDir: ".cache/@11ty/img/",
		urlPath: "/img/built/",
	});

	eleventyConfig.on("eleventy.after", () => {
		fs.cpSync(".cache/@11ty/img/", "_site/img/built/", { recursive: true });
	});
}

Marginally related to 11ty/eleventy#3573

This is useful as some build servers persist .cache folder for you for free: https://www.11ty.dev/docs/deployment/#persisting-cache

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions