-
Notifications
You must be signed in to change notification settings - Fork 3
/
.eleventy.js
154 lines (140 loc) · 4.55 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright 2020-2022 G-Labs. All Rights Reserved.
* https://zuixjs.github.io/zuix
*
* Licensed under the MIT license. See LICENSE file.
*
*/
/*
*
* This file is part of
* zUIx, Javascript library for component-based development.
* https://zuixjs.github.io/zuix
*
* @author Generoso Martello - https://github.com/genemars
* @version 1.0
*
*/
const path = require('path');
const compress = require('compression');
// 11ty
const {EleventyRenderPlugin} = require("@11ty/eleventy");
// zuix.js
const zuix11ty = require('./.eleventy-zuix');
const zuixConfig = zuix11ty.getZuixConfig();
// LESS CSS compiler
const less = require('less');
const lessConfig = require(process.cwd() + '/.lessrc');
// Linter (ESLint)
const Linter = require('eslint').Linter;
const linter = new Linter();
const lintConfig = require(process.cwd() + '/.eslintrc');
// Minifier
//const { minify } = require("terser");
// Keep track of changed files for zUIx.js post-processing
let browserSync;
module.exports = function(eleventyConfig) {
eleventyConfig.setWatchJavaScriptDependencies(false);
eleventyConfig.addPlugin(EleventyRenderPlugin);
// Add ignores
[...zuixConfig.ignoreFiles, ...zuixConfig.componentsFolders].forEach((f) => {
f = path.join(zuixConfig.sourceFolder, f);
eleventyConfig.ignores.add(f);
});
// Ignore `zuix-editor` if mode is 'production'
if (process.env.NODE_ENV === 'production') {
eleventyConfig.ignores.add(path.join(zuixConfig.sourceFolder, 'editor/*'));
}
// Ignore "copy" files, because they are handled by zuix11ty
zuixConfig.copyFiles.forEach((f) => {
f = path.join(zuixConfig.sourceFolder, f);
eleventyConfig.ignores.add(f);
});
// from https://github.com/kkgthb/web-site-11ty-03-netlify-function/blob/main/.eleventy.js
// See if this helps with things that do not refresh
//module.exports = function (eleventyConfig) {
// eleventyConfig.setUseGitIgnore(false);
//};
// Make Liquid capable of rendering "partials"
eleventyConfig.setLiquidOptions({
cache: false,
dynamicPartials: true,
strictFilters: false,
});
// Add custom file types and handlers
eleventyConfig.addTemplateFormats([ 'less', 'css', 'js' ]);
eleventyConfig.addExtension('less', {
read: true,
outputFileExtension: 'css',
compile: (content, path) => () => {
let output;
less.render(content, lessConfig, function(error, lessOutput) {
// TODO: handle and report 'error'
output = lessOutput;
});
return output.css;
}
});
// Add linter to report code errors
eleventyConfig.addLinter('eslint', function(content, inputPath, outputPath) {
if( inputPath.endsWith('.js') ) {
// TODO: collect and report at the end of the build (inside 'afterBuild' event handler)
const issues = linter.verify(content, lintConfig, inputPath);
if (issues.length > 0) {
console.log('[11ty] "%s" linter result', inputPath)
}
issues.forEach(function(m) {
if (m.fatal || m.severity > 1) {
console.error(' Error: %s (%s:%s)', m.message, m.line, m.column);
} else {
console.warn(' Warning: %s (%s:%s)', m.message, m.line, m.column);
}
});
}
});
// Add any BrowserSync config option here
eleventyConfig.setServerOptions({
module: "@11ty/eleventy-server-browsersync",
//reloadDelay: 2000,
files: [ ...zuixConfig.componentsFolders ],
notify: false,
cors: true,
middleware: [compress(), function(req, res, next) {
res.setHeader('Set-Cookie', 'SameSite=Lax; Secure');
next();
}],
callbacks: {
ready: function(err, bs) {
// store a local reference of BrowserSync object
browserSync = bs;
// setup zuix-11ty watcher
zuix11ty.startWatcher(eleventyConfig, browserSync.publicInstance);
}
},
/*
snippet: false,
snippetOptions: {
rule: {
match: /<head[^>]*>/i,
fn: function(snippet, match) {
return match + snippet;
}
}
}*/
});
zuix11ty.configure(eleventyConfig);
// Return 11ty configuration options:
return {
pathPrefix: zuixConfig.baseUrl,
dir: {
input: zuixConfig.sourceFolder,
output: zuixConfig.buildFolder,
data: zuixConfig.dataFolder,
includes: zuixConfig.includesFolder,
layouts: path.join(zuixConfig.includesFolder, "layouts")
},
//htmlTemplateEngine: false, // 'liquid'
markdownTemplateEngine: 'liquid',
templateFormats: ['html', 'liquid', 'ejs', 'md', 'hbs', 'mustache', 'haml', 'pug', 'njk', '11ty.js']
}
};