Skip to content

Commit c6051e3

Browse files
committed
feat: lay down prep work for adding full on service worker support to Pattern Lab's UI. Cache busting logic will likely need to get added but the overall setup being added pretty much works!
1 parent e736dd6 commit c6051e3

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/uikit-workshop/gulpfile.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const inlinesource = require('gulp-inline-source');
88
const path = require('path');
99
const { buildCriticalCSS } = require('./penthouse');
1010

11+
// @todo: uncomment once cache-busting strategy in place.
12+
// const workboxBuild = require('workbox-build');
13+
1114
/* load the plugins */
1215
const gulpLoadPlugins = require('gulp-load-plugins');
1316
const plugins = gulpLoadPlugins({ scope: ['devDependencies'] });
@@ -181,6 +184,17 @@ gulp.task('build:js-pattern', ['clean', 'build:js-viewer'], function() {
181184
.pipe(copyPublic('styleguide/js'));
182185
});
183186

187+
// @todo: re-enable once cache busting strategy in place
188+
// gulp.task('service-worker', ['build:html'], function() {
189+
// return workboxBuild.generateSW({
190+
// globDirectory: 'dist',
191+
// globPatterns: ['**/*.{html,json,js,css}'],
192+
// swDest: 'dist/sw.js',
193+
// clientsClaim: true,
194+
// skipWaiting: true,
195+
// });
196+
// });
197+
184198
gulp.task(
185199
'default',
186200
[
@@ -190,6 +204,7 @@ gulp.task(
190204
'build:js-pattern',
191205
'build:html',
192206
'prebuild:html',
207+
// 'service-worker', // @todo: uncomment once cache-busting strategy in place
193208
],
194209
function() {
195210
if (args.watch !== undefined) {

packages/uikit-workshop/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"imagemin-pngcrush": "^5.1.0",
4646
"main-bower-files": "^2.13.1",
4747
"penthouse": "^1.6.2",
48+
"workbox-build": "^3.4.1",
4849
"yargs": "^12.0.1"
4950
},
5051
"publishConfig": {

packages/uikit-workshop/src/html/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
}
113113
});
114114

115+
// Check that service workers are registered
116+
// @todo: uncomment once cache-busting strategy is in place
117+
// if ('serviceWorker' in navigator) {
118+
// // Use the window load event to keep the page load performant
119+
// window.addEventListener('load', () => {
120+
// navigator.serviceWorker.register('/sw.js');
121+
// });
122+
// }
115123
</script>
116124

117125
</body>

0 commit comments

Comments
 (0)