-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.eleventy.js
80 lines (67 loc) · 2.08 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
import CleanCSS from "clean-css";
import fs from "fs-extra";
import htmlmin from "html-minifier";
import { JSDOM } from "jsdom";
import * as sass from "sass";
import { minify } from "terser";
export default function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("images")
eleventyConfig.addPassthroughCopy("missiles")
eleventyConfig.addPassthroughCopy("src")
eleventyConfig.addPassthroughCopy({
"node_modules/three/examples/js/controls/OrbitControls.js": "vendor/OrbitControls.js",
})
eleventyConfig.addPassthroughCopy({
"node_modules/d3-array/dist/d3-array.min.js": "vendor/d3-array.js",
})
eleventyConfig.addPassthroughCopy({
"node_modules/d3-geo/dist/d3-geo.min.js": "vendor/d3-geo.js",
})
eleventyConfig.addPassthroughCopy({
"node_modules/three/build/three.min.js": "vendor/three.js",
})
eleventyConfig.addTransform(
"htmlmin",
function(content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
const dom = new JSDOM(content)
// const style = dom.window.document.createElement("style")
// style.type = "text/css"
// style.innerHTML = fs.readFileSync(`_site/style-${version}.css`, "utf-8")
// dom.window.document.head.appendChild(style)
//const pictures = dom.window.document.querySelectorAll("p > picture")
//for (const p of pictures) {
//p.parentElement.replaceWith(p)
//}
const html = dom.serialize()
return htmlmin.minify(html, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
})
}
return content
}
)
eleventyConfig.addFilter(
"scss",
function(scss) {
let css = sass.renderSync({
data: scss,
}).css
css = new CleanCSS({}).minify(css).styles
return css
}
)
eleventyConfig.addNunjucksAsyncFilter(
"terser",
function(js, callback) {
minify(js).then(({ code }) => callback(null, code))
}
)
eleventyConfig.addWatchTarget("./style.scss")
const dir = {
includes: "_html",
}
return { dir }
}