-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
72 lines (67 loc) · 2.09 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
import browserslist from 'browserslist';
import { transform, browserslistToTargets } from 'lightningcss';
import markdownIt from 'markdown-it';
import { eleventyImagePlugin } from '@11ty/eleventy-img';
import webc from '@11ty/eleventy-plugin-webc';
import syntaxHighlight from '@11ty/eleventy-plugin-syntaxhighlight';
import renderSvg from './lib/renderSvg.js';
import findCollectionItem from './lib/findCollectionItem.js';
async function transformCSS(content) {
if (this.type !== 'css') {
return content;
}
const targets = browserslistToTargets(browserslist('> 0.25% and not dead'));
const { code } = transform({
code: Buffer.from(content),
minify: true,
sourceMap: false,
targets,
});
return code;
}
export default function(eleventyConfig) {
// copy the assets folder to the output directory
eleventyConfig.addPassthroughCopy('src/assets');
// Reloading on css changes
eleventyConfig.addWatchTarget('src/styles/*.css');
// make functions available globally in templates
eleventyConfig.addJavaScriptFunction('renderSvg', renderSvg);
eleventyConfig.addJavaScriptFunction('findCollectionItem', findCollectionItem);
// support eleventy-image https://www.11ty.dev/docs/plugins/image
eleventyConfig.addPlugin(eleventyImagePlugin, {
formats: ['webp'],
widths: [800, 1600],
urlPath: '/assets/images/',
defaultAttributes: {
sizes: '100vw',
loading: 'lazy',
},
});
// load all components added to the src/components directory
eleventyConfig.addPlugin(webc, {
components: [
'src/components/**/*.webc',
'npm:@11ty/eleventy-img/*.webc',
],
bundlePluginOptions: {
transforms: [transformCSS],
},
});
// Support markdown templates in webc using <template webc:type="11ty" 11ty:type="md">
eleventyConfig.setLibrary('md', markdownIt({
html: true,
breaks: true,
linkify: true,
}));
// add syntax highlighting to code blocks
eleventyConfig.addPlugin(syntaxHighlight);
return {
dir: {
layouts: 'layouts',
includes: 'components',
data: 'data',
input: 'src',
output: 'dist'
}
}
};