add build-sw.js

This commit is contained in:
Harvey authored and Harvey Zack committed 2022-04-26 11:53:11 +08:00
1 parent be88f55657
commit 7e58717e07
7 files changed
+226 -167

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
const { generateSW } = require('workbox-build');
generateSW({
globDirectory: 'docs/',
globPatterns: ['assets/**/*.{css,woff2,png,svg,jpg,js}'],
maximumFileSizeToCacheInBytes: 1024 * 1024 * 5,
swDest: 'docs/sw.js',
sourcemap: false,
}).then(({ count, size, warnings }) => {
if (warnings.length > 0) {
console.warn('Warnings encountered while generating a service worker:', warnings.join('\n'));
}
console.log(`Generated a service worker, which will precache ${count} files, totaling ${size} bytes.`);
});