-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
117 lines (104 loc) · 2.37 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
105
106
107
108
109
110
111
112
113
114
115
116
117
const { src, dest, task, series, watch } = require("gulp");
const exec = require("child_process").exec;
const htmlreplace = require("gulp-html-replace");
const csso = require("gulp-csso");
const clean = require("gulp-clean");
const rename = require("gulp-rename");
const md5File = require("md5-file");
/**
* Task: Tailwind
*/
task("tailwind", function (cb) {
const command =
"npx tailwindcss -i ./src/assets/css/tailwind-blog.css -o ./public/assets/dist/css/tailwind-blog.css";
exec(command, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
/**
* Task: Prettier
*/
task("pretty", function (cb) {
const command = "npx prettier --write src/pages/*.html";
exec(command, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
/**
* Task: Export images and pages to public
*/
task("build-pages", function () {
return src("./src/pages/*.html").pipe(dest("./public/"));
});
/**
* Task: Build images
*/
task("build-images", function () {
return src("./src/assets/images/*.{png,svg,ico,jpg,jpeg}").pipe(
dest("./public/assets/images/")
);
});
/**
* Task: Build favicons
*/
task("build-favicons", function () {
return src("./*.{png,svg,webmanifest}").pipe(dest("public"));
});
/**
* Task: Build css version
*/
task("build-css-version", function () {
const baseFilePath = "./public/assets/dist/css/tailwind-blog.css";
const hash = md5File.sync(baseFilePath);
return src(baseFilePath)
.pipe(csso())
.pipe(rename(`tailwind-blog-${hash}.css`))
.pipe(dest("./public/assets/dist/css/"));
});
/**
* Task: Build html updates
*/
task("build-html-updates", function () {
const hash = md5File.sync("./public/assets/dist/css/tailwind-blog.css");
return src("./public/*.html")
.pipe(
htmlreplace({
css: `/assets/dist/css/tailwind-blog-${hash}.css`,
})
)
.pipe(dest("public/"));
});
/**
* Task: Clean
*/
task("clean", function () {
return src("./public/assets/dist/css/*.css").pipe(clean());
});
/**
* Task: watch
*/
task("watch", function () {
watch("./src/pages/*.html", series("build"));
});
/**
* Task: Build
*/
task(
"build",
series(
"clean",
"tailwind",
"build-pages",
"build-images",
"build-css-version",
"build-html-updates"
)
);
/**
* Task: Default
*/
task("default", series("build"));