generated from woodcox/11ty-sass-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
81 lines (70 loc) · 2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const sass = require("sass");
const pluginWebc = require("@11ty/eleventy-plugin-webc");
const { EleventyRenderPlugin } = require("@11ty/eleventy");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
const now = String(Date.now());
const solidShortcode = require('./config/shortcodes/solidify.js');
const esbuildPipeline = require('./config/build/esbuild.js');
const purgecssPipeline = require('./config/build/purgecss.js');
const path = require("path");
const manifest = require('./src/_data/manifest.json');
const isProd = process.env.ELEVENTY_ENV === 'prod' ? true : false;
const TEMPLATE_ENGINE = "liquid";
module.exports = function (eleventyConfig) {
// DEV SERVER
eleventyConfig.setServerOptions({
port: 8080,
watch: ["dist/app/*.css", "dist/app/*.js"],
liveReload: true,
domDiff: true,
});
// WATCH
// esbuild is also watching the js & jsx files
eleventyConfig.watchIgnores.add("./src/_data/manifest.json");
eleventyConfig.watchIgnores.add("./src/_data/buildmeta.json");
// BUILD HOOK
eleventyConfig.on("eleventy.before", esbuildPipeline);
if (isProd){
eleventyConfig.on("eleventy.after", purgecssPipeline);
};
// PLUGINS
eleventyConfig.addPlugin(pluginWebc, {
components: "src/_includes/components/*.webc",
});
// to use other templates like liquid and nunjunks
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
// SHORTCODES & FILTERS
// Add cache busting by using {{ 'myurl' | version }}
eleventyConfig.addFilter("version", (url) => {
const [urlPart, paramPart] = url.split("?");
const params = new URLSearchParams(paramPart || "");
params.set("v", `${now}`);
return `${urlPart}?${params}`;
});
// Use this filter only if the asset is processed by esbuild and is in _data/manifest.json. Use {{ 'myurl' | hash }}
eleventyConfig.addFilter("hash", (url) => {
const urlbase = path.basename(url);
const [basePart, ...paramPart] = urlbase.split(".");
const urldir = path.dirname(url);
let hashedBasename = manifest[basePart];
return `${urldir}/${hashedBasename}`;
});
/* Use filter to resolve promises from async functions. No more [object Promise] in your templates. {{ myAsyncFunction() | await }} */
eleventyConfig.addFilter("await", async promise => {
return promise;
});
eleventyConfig.addPairedShortcode("solid", solidShortcode);
// Let Eleventy transform HTML files as liquidjs
// So that we can use .html instead of .liquid
return {
dir: {
input: "src",
output: "dist",
data: "_data",
},
templateFormats: ["html", "md", TEMPLATE_ENGINE],
markdownTemplateEngine: TEMPLATE_ENGINE,
htmlTemplateEngine: TEMPLATE_ENGINE,
};
};