-
Notifications
You must be signed in to change notification settings - Fork 33
/
gulpfile.js
77 lines (73 loc) · 2.33 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
const gulp = require("gulp");
const clean = require("gulp-clean");
const shell = require("gulp-shell");
const workbox = require("workbox-build");
gulp.task("clean", function () {
return gulp.src("public", { read: false, allowEmpty: true })
.pipe(clean());
});
gulp.task("hugo-build", shell.task(["hugo --gc"]));
gulp.task("generate-service-worker", () => {
return workbox.generateSW({
cacheId: "bmpi",
globDirectory: "./public",
globPatterns: [
"**/*.{css,js,eot,ttf,woff,woff2,otf}"
],
swDest: "./public/sw.js",
modifyURLPrefix: {
"": "/"
},
clientsClaim: true,
skipWaiting: true,
ignoreURLParametersMatching: [/./],
offlineGoogleAnalytics: true,
maximumFileSizeToCacheInBytes: 50 * 1024 * 1024,
runtimeCaching: [
{
urlPattern: /(?:\/)$/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "html",
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 7,
},
},
},
{
urlPattern: /\.(?:png|jpg|jpeg|gif|bmp|webp|svg|ico)$/,
handler: "CacheFirst",
options: {
cacheName: "images",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
{
urlPattern: /\.(?:mp3|wav|m4a)$/,
handler: "CacheFirst",
options: {
cacheName: "audio",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
},
{
urlPattern: /\.(?:m4v|mpg|avi)$/,
handler: "CacheFirst",
options: {
cacheName: "videos",
expiration: {
maxEntries: 1000,
maxAgeSeconds: 60 * 60 * 24 * 365,
},
},
}
],
});
});
gulp.task("build", gulp.series("clean", "hugo-build", "generate-service-worker"));