-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 1.05 KB
/
index.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
const minify = require("html-minifier").minify;
const path = require("path");
const fs = require("fs");
module.exports = function htmlMinifierMiddleware(options) {
options = options || {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true
};
return reptar => {
for (const relativePath in reptar.destination) {
if (path.extname(relativePath) !== ".html") {
continue;
}
const file = reptar.destination[relativePath];
if (file.filtered) {
continue;
}
const destinationPath = path.join(
reptar.config.get("path.destination"),
relativePath
);
var fileContent;
try {
fileContent = fs.readFileSync(destinationPath, "utf8");
} catch (e) {
console.log(file);
throw e;
}
const newContent = minify(fileContent, options);
fs.writeFileSync(destinationPath, newContent, "utf8");
}
};
};