-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
60 lines (52 loc) · 1.75 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
const htmlmin = require('html-minifier')
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/img")
eleventyConfig.addPassthroughCopy("src/favicon.ico")
eleventyConfig.addPassthroughCopy("src/site.webmanifest")
eleventyConfig.addWatchTarget("src/styles")
eleventyConfig.on('beforeBuild', () => {
const postcss = require('postcss')
const atImport = require('postcss-import')
const nesting = require('tailwindcss/nesting')
const tailwindcss = require('tailwindcss')
const autoprefixer = require('autoprefixer')
const fs = require('fs')
fs.mkdirSync('_site/styles/', { recursive: true })
fs.readFile('src/styles/main.css', (err, css) => {
postcss([atImport,nesting,tailwindcss,autoprefixer])
.process(css, { from: 'src/styles/main.css', to: '_site/styles/main.min.css' })
.then(result => {
fs.writeFile('_site/styles/main.min.css', result.css, (err) => {
if (err) throw err;
});
})
})
})
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
if (process.env.NODE_ENV === "production" &&
outputPath && outputPath.endsWith('.html')) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified
}
return content
})
eleventyConfig.addShortcode('uid', () => Date.now().toString(36))
eleventyConfig.addShortcode('year', () => `${new Date().getFullYear()}`)
return {
dir: {
input: 'src',
output: '_site',
data: '_data',
includes: '_includes',
},
templateFormats: [
'md',
'njk',
],
htmlTemplateEngine: 'njk'
}
}