-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
81 lines (72 loc) · 2.29 KB
/
gulpfile.js
File metadata and controls
81 lines (72 loc) · 2.29 KB
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
const gulp = require("gulp");
const path = require("path");
const fs = require("fs");
const svg2png = require('gulp-svg2png');
const rename = require("gulp-rename");
const responsive = require('gulp-responsive');
const logger = require("gulp-logger");
const workbox = require("workbox-build");
gulp.task("favicon-512", () => {
return gulp.src('./src/assets/**/*.svg')
.pipe(svg2png({
width: 512,
height: 512
}))
.pipe(rename({
suffix: "-512"
}))
.pipe(gulp.dest('./src/assets/generated'));
});
gulp.task("favicon", gulp.series("favicon-512", () => {
return gulp.src("./src/assets/generated/icon-512.png")
.pipe(responsive({
"icon-512.png": [
{
height: 64,
width: 64,
rename: "icon-64.png"
},
{
height: 32,
width: 32,
rename: "icon-32.png"
}
]
}))
.pipe(gulp.dest("./src/assets/generated"))
}));
gulp.task("noJekyll", () => {
return new Promise((res) => {
fs.writeFile(path.join("./dist", ".nojekyll"), "", () => {
res();
});
});
});
var stagingDirectory = "./dist"
gulp.task('generate-service-worker', () => {
return workbox.generateSW({
globDirectory: stagingDirectory,
globPatterns: ["**\/*.{html,js,css,jpg,webmanifest,png}"],
swDest: `${stagingDirectory}/sw.js`,
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: new RegExp('https://fonts.googleapis.com'),
handler: 'staleWhileRevalidate'
}, {
urlPattern: new RegExp("https://fonts.gstatic.com"),
handler: 'staleWhileRevalidate'
},
{
urlPattern: new RegExp("\/"),
handler: 'staleWhileRevalidate'
}
]
}).then(() => {
console.info('Service worker generation completed.');
}).catch((error) => {
console.warn('Service worker generation failed: ' + error);
});
});
gulp.task("default", gulp.series(gulp.parallel("favicon", "noJekyll"), "generate-service-worker"));