-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
58 lines (48 loc) · 1.84 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
const { renderReactComponent } = require('./utils');
const htmlmin = require('html-minifier');
module.exports = eleventyConfig => {
eleventyConfig.on('beforeBuild', function () {
// reset the counter for each new build
// otherwise, it'll count up higher and higher on every live reload
idCounter = 0;
});
let idCounter = 0;
// copy all our /components to the output directory
// so Vite can find them. Very important step!
eleventyConfig.addPassthroughCopy({ './src/scripts': 'scripts' });
eleventyConfig.addPassthroughCopy({ './src/styles': 'styles' });
eleventyConfig.addPassthroughCopy({ './src/public': 'public' });
eleventyConfig.addNunjucksAsyncShortcode('react', async (componentPath, options = {}) => {
idCounter += 1;
const hydrate = options.hydrate === false ? false : true;
const mount = options.mount || null;
const data = options.data || {};
console.log(options.hydrate, hydrate, mount, data);
return await renderReactComponent(idCounter, componentPath, hydrate, mount, data);
});
eleventyConfig.addShortcode('js', function (componentPath) {
return `<script type="module" src=${JSON.stringify(componentPath)}></script>`;
});
eleventyConfig.addShortcode('scss', function (componentPath) {
return `<link rel="stylesheet" href=${JSON.stringify(componentPath)} />`;
});
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (outputPath && outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
return {
dir: {
input: 'src/pages',
layouts: '_includes/layouts',
output: '_dev',
},
};
};