-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
104 lines (91 loc) · 2.34 KB
/
gulpfile.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
/* eslint-disable space-before-function-paren */
'use strict';
const SRC_HTML = 'public/**/*.html';
const SRC_CSS = 'public/**/*.css';
const SRC_JS = 'public/**/*.js';
const SRC_JSON = 'public/**/*.json';
const DEST = 'public';
const gulp = require('gulp');
const postCSS = require("gulp-postcss");
const postHTML = require('gulp-posthtml');
const htmlmin = require('gulp-htmlmin');
const htmltidy = require('gulp-htmltidy');
const minify = require('gulp-minify');
const jsonminify = require('gulp-jsonminify');
const postHtmlPlugins = [
require("posthtml-img-autosize")({ root: DEST, processEmptySize: true }),
require("posthtml-alt-always")({}),
require("posthtml-align-style")({}),
require("posthtml-avif-webp")({ root: DEST })
];
const postHtmlPluginsSecondRun = [
require("htmlnano")({
mergeStyles: true,
// breaks my beautiful header image :'-(
minifySvg: false,
// does not work as expected
// minifyUrls: process.env.IMG_BASE_URL,
}),
require("posthtml-externalize-styles")({ root: DEST }),
];
const htmltidyConfig = {
doctype: 'html5',
hideComments: true,
wrap: 0,
indent: true,
indentSpaces: 2,
indentWithTabs: true,
tabSize: 2,
keepTabs: true,
clean: true,
joinStyles: true,
uppercaseAttributes: 'preserve',
priorityAttributes: 'id,class,name,href,src',
tidyMark: false
};
const htmlminOptions = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: false,
minifyCSS: true,
minifyJS: true,
removeComments: true,
removeStyleLinkTypeAttributes: true
};
const minifyConfig = {
ext: {
src: '-debug.js',
min: '.js'
}
}
function html() {
return gulp.src(SRC_HTML)
.pipe(postHTML(postHtmlPlugins))
.pipe(htmltidy(htmltidyConfig))
.pipe(htmlmin(htmlminOptions))
.pipe(postHTML(postHtmlPluginsSecondRun))
.pipe(gulp.dest(DEST));
};
function javascript() {
return gulp.src(SRC_JS)
.pipe(minify(minifyConfig))
.pipe(gulp.dest(DEST));
};
function json() {
return gulp.src(SRC_JSON)
.pipe(jsonminify())
.pipe(gulp.dest(DEST));
};
function css() {
return gulp
.src(SRC_CSS)
.pipe(
postCSS([
require("cssnano")({ preset: "default" }), // advanced
])
)
.pipe(gulp.dest(DEST));
}
const build = gulp.series(gulp.parallel(html, javascript, json), css);
exports.html = html;
exports.default = build;