-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
66 lines (52 loc) · 2.09 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// generate shorcode for img tag with srcset
const Image = require("@11ty/eleventy-img");
//Ex: {% image "cat.jpg", "photo of my tabby cat" %}
// inject SVG shortcode
const svgContents = require("eleventy-plugin-svg-contents");
// 11ty navigation plugin
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
// const eleventySass = require("eleventy-sass");
module.exports = function (eleventyConfig) {
// eleventyConfig.addPlugin(eleventySass);
eleventyConfig.addWatchTarget("./src");
// Copy dist/ files from laravel mix
eleventyConfig.addPassthroughCopy("dist/"); // path is relative from root
eleventyConfig.addPassthroughCopy("src/img"); // path is relative from root
eleventyConfig.addPassthroughCopy("src/assets"); // path is relative from root
// Plugins
eleventyConfig.addPlugin(svgContents); // svg injection
eleventyConfig.addPlugin(eleventyNavigationPlugin); // 11ty navigation plugin
// Important for watch: Eleventy will not add a watch for files or folders that
// are in .gitignore (--> dist/),unless setUseGitIgnore is turned off. See this chapter:
// https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets
eleventyConfig.setUseGitIgnore(false);
// Watch for changes (and reload browser)
eleventyConfig.addWatchTarget("./src/assets"); // normal (static) assets
eleventyConfig.addWatchTarget("./dist"); // laravel-mix output changes
// Add image shortcode
eleventyConfig.addShortcode("image", async function(src, alt, sizes) {
let metadata = await Image(src, {
widths: [300, 600],
formats: ["webp", "auto"],
urlPath: "/img/",
outputDir: "./public/img/", // passthrough below didn't work, write to output dir by now
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on a missing alt (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
});
return {
pathPrefix: "/",
dir: {
input: "src",
output: "public",
layouts: "_layouts",
includes: "_includes",
},
};
};