-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
41 lines (37 loc) · 1.27 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
const cleanCss = require('clean-css');
const uglifyJS = require('uglify-js');
const htmlMin = require('html-minifier');
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({'src/_includes/assets': '/assets'});
eleventyConfig.ignores.add("./src/savedCode.html");
eleventyConfig.addTransform('minifyHtml', (code, outputPath) => {
if (outputPath.endsWith('.html')) {
const minified = htmlMin.minify(code, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyJS: true
});
return minified;
}
return code;
});
eleventyConfig.addFilter('minifyCss', code => new cleanCss({}).minify(code).styles);
eleventyConfig.addFilter('minifyJs', code => {
let minified = uglifyJS.minify(code);
if (minified.error) {
console.log('Uglify ES error: ', minified.error);
return code;
}
return minified.code;
});
eleventyConfig.addFilter('removeIndexHtml', url => url.replace(/index.html$/, ''));
return {
dir: {
input: 'src',
includes: '_includes',
output: '_site',
data: '_data'
},
};
};