-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
74 lines (63 loc) · 2.17 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
67
68
69
70
71
72
73
74
const path = require('path');
const buildSystem = require('@cagov/11ty-build-system');
const { globPlugin } = require('esbuild-plugin-glob');
// Filters
const markdownFilter = require('./src/filters/markdownFilter.js');
const sortByOrder = require('./src/filters/sortByOrder.js');
// Plugins
const svgSprite = require('eleventy-plugin-svg-sprite');
// Transforms
const htmlMinTransform = require('./src/transforms/html-min-transform.js');
const purgeCSS = require('./src/transforms/css-purge-inline.js');
// Create a helpful production flag
const isProduction = process.env.NODE_ENV === 'production';
module.exports = (config) => {
// Set directories to pass through to the dist folder
config.addPassthroughCopy('./src/images/');
config.addPassthroughCopy('./src/fonts/');
config.addWatchTarget('./src/js/');
// Add filters
config.addFilter('markdownFilter', markdownFilter);
config.addFilter('sortByOrder', sortByOrder);
// Add Shortcodes
config.addShortcode('icon', require('./src/shortcodes/icon.js'));
config.addShortcode('picture', require('./src/shortcodes/picture.js'));
config.addShortcode('script', require('./src/shortcodes/script.js'));
// Plugins
config.addPlugin(svgSprite, {
path: './src/icons', // relative path to SVG directory
outputFilepath: './dist/icons/icons.svg',
});
config.addPlugin(buildSystem, {
processors: {
esbuild: {
watch: ['src/js/**/*'],
options: {
entryPoints: [path.resolve(__dirname, 'src/js/**/*.js')],
bundle: true,
minify: isProduction,
outdir: 'dist/js',
splitting: true,
format: 'esm',
plugins: [globPlugin()],
},
},
},
});
// Only minify HTML if we are in production because it slows builds _right_ down
if (isProduction) {
config.addTransform('htmlmin', htmlMinTransform);
config.addTransform('purgeCSS', purgeCSS);
}
// Tell 11ty to use the .eleventyignore and ignore our .gitignore file
config.setUseGitIgnore(false);
return {
markdownTemplateEngine: 'njk',
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
dir: {
input: 'src',
output: 'dist',
},
};
};