Add files using passthrough file copy
Eleventy will only process specific filetypes. For assets like images, CSS and JavaScript, you need to set up passthrough copy to copy those files into your _site directory each time Eleventy is run.
Directions
-
Create a folder called css, and inside create a file called style.css
-
Inside style.css add some styles:
body {
font-family: sans-serif;
}
- In _includes/base.njk, link to your styles in the head:
<link href="/css/style.css" rel="stylesheet">
- Create a file in your project root called .eleventy.js and add the following:
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("css");
};
-
Visit your index page at https://localhost:8080 and your styles should now be linked.
-
To add passthrough for images and JS files (in directories named img and js), add the following to .eleventy.js, within the
module.exports
function:
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("js");