Lesson 5: Passthrough basics

A quick tutorial on telling Eleventy to copy files over to your website output.

In our project folder we have an src folder and a dist folder. The src folder contains source files, which are mainly code, but also include static files like images.

We’re going to want some of those static files in our output folder and luckily, Eleventy makes this pretty straightforward with Passthrough file copy.

In this lesson, we’re going to make our images work by telling Eleventy to copy our image files over to our dist folder.

Our current state permalink

If you go to http://localhost:8080 now, it should look like this:

Some structured HTML content with a broken image that reveals thealt text

There’s an image in there, but you’ll notice it’s not rendering, and it’s showing the image alternative text instead.

This is because our images never got copied over to our dist folder, which is where this localhost:8080 serves the local site from.

Adding passthrough permalink

Open up eleventy-from-scratch/.eleventy.js in your text editor and on the first line of the function (right below module.exports = config => { ) add this line:

Code language
JavaScript
// Set directories to pass through to the dist folder
config.addPassthroughCopy('./src/images/');

Now, if you open up http://localhost:8080, it should look like this:

The same homepage with an image of toast that’s now successfullyloaded

Wrapping up permalink

A short but sweet lesson!

You can copy anything you like over with passthrough copy. It’s how I usually do stuff like CSS for very simple projects to reduce the need for further build steps.

Let’s move on and write some more code.