-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
83 lines (70 loc) · 1.96 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
75
76
77
78
79
80
81
82
83
const bundlerPlugin = require("@11ty/eleventy-plugin-bundle");
const webcPlugin = require("@11ty/eleventy-plugin-webc");
const cssMinifier = require("clean-css");
const htmlMinifier = require("html-minifier-terser");
const jsMinifier = require("terser");
const root_folder = "src";
async function minifyCSS(content) {
if (this.type === "css") {
options = {
level: {
1: {
specialComments: 0,
},
},
};
return new cssMinifier(options).minify(content).styles;
}
return content;
}
async function minifyHTML(content) {
if (this.page.outputPath.endsWith(".html")) {
options = {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
// conservativeCollapse: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
minifyURLs: true,
preventAttributesEscaping: true,
processConditionalComments: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
trimCustomFragments: true,
useShortDoctype: true,
};
return htmlMinifier.minify(content, options);
}
return content;
}
async function minifyJS(content) {
if (this.type === "js") {
minified = await jsMinifier.minify(content);
return minified.code;
}
return content;
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(bundlerPlugin, {
transforms: [minifyCSS, minifyJS],
});
eleventyConfig.addPlugin(webcPlugin, {
components: root_folder + "/_includes/components/**/*.webc",
});
eleventyConfig.addTransform("Minify HTML", minifyHTML);
return {
dir: {
input: root_folder,
},
htmlTemplateEngine: "webc",
markdownTemplateEngine: "webc",
};
};