-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
66 lines (55 loc) · 1.71 KB
/
eleventy.config.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
import dotenv from "dotenv";
import markdownIt from "markdown-it";
import eleventyNavigation from "@11ty/eleventy-navigation";
import pluginWebc from "@11ty/eleventy-plugin-webc";
import { EleventyRenderPlugin } from "@11ty/eleventy";
import { writeFileSync } from "fs";
import minify from "./lib/minify.js";
import siteData from "./src/_data/site.js";
if (process.env.BUILD_ENV !== "production") {
dotenv.config();
}
export default async function (eleventyConfig) {
eleventyConfig.setQuietMode(true);
eleventyConfig.setLibrary(
"md",
markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true,
}),
);
// Plugins
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(eleventyNavigation);
eleventyConfig.addPlugin(pluginWebc, {
components: "src/_includes/components/**/*.webc",
});
// Functions
eleventyConfig.addJavaScriptFunction("absoluteURL", (path) => {
return `${siteData.baseUrl}${path}`;
});
// Static files
eleventyConfig.addPassthroughCopy("src/img");
eleventyConfig.addPassthroughCopy("src/fonts");
eleventyConfig.addPassthroughCopy("src/manifest.json");
eleventyConfig.addPassthroughCopy("src/robots.txt");
// After build
eleventyConfig.on("eleventy.after", async ({ results }) => {
if (process.env.BUILD_ENV !== "production") {
// skip minification in development
return;
}
for (const result of results) {
const { content, outputPath } = result;
const minified = await minify(content, outputPath);
writeFileSync(outputPath, minified);
}
});
return {
dir: { input: "src", output: "dist" },
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
}