1+ const gulp = require ( "gulp" ) ;
2+ const clean = require ( "gulp-clean" ) ;
3+ const shell = require ( "gulp-shell" ) ;
4+ const workbox = require ( "workbox-build" ) ;
5+
6+ gulp . task ( "clean" , function ( ) {
7+ return gulp . src ( "public" , { read : false , allowEmpty : true } )
8+ . pipe ( clean ( ) ) ;
9+ } ) ;
10+
11+ gulp . task ( "hugo-build" , shell . task ( [ "hugo --gc" ] ) ) ;
12+
13+ gulp . task ( "generate-service-worker" , ( ) => {
14+ return workbox . generateSW ( {
15+ cacheId : "bmpi" ,
16+ globDirectory : "./public" ,
17+ globPatterns : [
18+ "**/*.{css,js,eot,ttf,woff,woff2,otf}"
19+ ] ,
20+ swDest : "./public/sw.js" ,
21+ modifyURLPrefix : {
22+ "" : "/"
23+ } ,
24+ clientsClaim : true ,
25+ skipWaiting : true ,
26+ ignoreURLParametersMatching : [ / ./ ] ,
27+ offlineGoogleAnalytics : true ,
28+ maximumFileSizeToCacheInBytes : 50 * 1024 * 1024 ,
29+ runtimeCaching : [
30+ {
31+ urlPattern : / (?: \/ ) $ / ,
32+ handler : "StaleWhileRevalidate" ,
33+ options : {
34+ cacheName : "html" ,
35+ expiration : {
36+ maxAgeSeconds : 60 * 60 * 24 * 7 ,
37+ } ,
38+ } ,
39+ } ,
40+ {
41+ urlPattern : / \. (?: p n g | j p g | j p e g | g i f | b m p | w e b p | s v g | i c o ) $ / ,
42+ handler : "CacheFirst" ,
43+ options : {
44+ cacheName : "images" ,
45+ expiration : {
46+ maxEntries : 1000 ,
47+ maxAgeSeconds : 60 * 60 * 24 * 365 ,
48+ } ,
49+ } ,
50+ } ,
51+ {
52+ urlPattern : / \. (?: m p 3 | w a v | m 4 a ) $ / ,
53+ handler : "CacheFirst" ,
54+ options : {
55+ cacheName : "audio" ,
56+ expiration : {
57+ maxEntries : 1000 ,
58+ maxAgeSeconds : 60 * 60 * 24 * 365 ,
59+ } ,
60+ } ,
61+ } ,
62+ {
63+ urlPattern : / \. (?: m 4 v | m p g | a v i ) $ / ,
64+ handler : "CacheFirst" ,
65+ options : {
66+ cacheName : "videos" ,
67+ expiration : {
68+ maxEntries : 1000 ,
69+ maxAgeSeconds : 60 * 60 * 24 * 365 ,
70+ } ,
71+ } ,
72+ }
73+ ] ,
74+ } ) ;
75+ } ) ;
76+
77+ gulp . task ( "build" , gulp . series ( "clean" , "hugo-build" , "generate-service-worker" ) ) ;
0 commit comments