generated from philhawksworth/eleventyone
-
Notifications
You must be signed in to change notification settings - Fork 28
/
.eleventy.js
47 lines (39 loc) · 1.25 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
const sass = require("sass");
const fs = require("fs-extra");
module.exports = function(eleventyConfig) {
// minify the html output
eleventyConfig.addTransform("htmlmin", require("./src/utils/minify-html.js"));
// compress and combine js files
eleventyConfig.addFilter("jsmin", function(code) {
const UglifyJS = require("uglify-es");
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});
// Compile Sass before a build
eleventyConfig.on("beforeBuild", () => {
let result = sass.renderSync({
file: "src/scss/styles.scss",
sourceMap: false,
outputStyle: "compressed",
});
fs.ensureDirSync('dist/css/');
fs.writeFile("dist/css/styles.css", result.css, (err) => {
if (err) throw err;
console.log("CSS generated");
});
});
return {
dir: {
input: "src/site",
output: "dist",
data: "_data"
},
templateFormats: ["njk", "md", "11ty.js"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk"
};
};