Eleventy: how to serve images?

Created on 8 Apr 2019  路  4Comments  路  Source: 11ty/eleventy

maybe something is missing from the docs, or maybe I'm stupid but I can't see how to get images to work.

I setup a simple site with an /img directory.
Images don't appear when serving the site or get copied to _site

searched for "images" on https://www.11ty.io/docs but can't find much. images

I _did_ find a couple of closed issues and so I tried the passThrough config:

https://www.11ty.io/docs/copy/

I tried both as templateFormats and passThrough files, neither works:

file : .eleventy.js

module.exports = function(eleventyConfig) {
  // Copy the `img/` directory
  eleventyConfig.addPassthroughCopy("img");

  return {
    passthroughFileCopy: true
  };
};

However it doesn't seem to actual copy the /img directory.
build output (naming the config to make sure it is finding it)

eleventy --config=.eleventy.js
Writing _site/README/index.html from ./README.md.
Processed 1 file in 0.18 seconds

The only thing I found to work is to put the images into _site directly.
Is this the recommended process? It seems if there was a build --clean then everything would get wiped out. I would also prefer to .gitignore the file site output.

It seems adding images to a site is the first thing people would do, so it would be nice if this was a little easier or at least clearer.

Most helpful comment

however it might still be worth making this more obvious on the docs (or a default images directory?) so new users don't have to hunt down pass through just to serve a static image.

All 4 comments

eleventy --version
0.8.1

update: works. somehow my .eleventy.js managed to get an invisible character at the end of the filename...

however it might still be worth making this more obvious on the docs (or a default images directory?) so new users don't have to hunt down pass through just to serve a static image.

Was this page helpful?
0 / 5 - 0 ratings