-
Notifications
You must be signed in to change notification settings - Fork 5
/
minify-html.cjs
39 lines (31 loc) 路 857 Bytes
/
minify-html.cjs
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
'use strict';
const { extname } = require('node:path');
const { minify } = require('html-minifier');
const config = require('../../config.cjs');
const isDevelopment = config.get('mode') !== 'production';
const minifyHtml = function (content) {
if (
!this.page.outputPath ||
!['.html', '.php'].includes(extname(this.page.outputPath)) ||
isDevelopment
) {
return content;
}
const result = minify(content, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
trimCustomFragments: true,
useShortDoctype: true,
});
return result;
};
module.exports = minifyHtml;