Skip to content

Instantly share code, notes, and snippets.

@dlebedynskyi
Created January 14, 2018 18:39
Show Gist options
  • Save dlebedynskyi/7f7cc85ca3f2846f1752939211cac30f to your computer and use it in GitHub Desktop.
Save dlebedynskyi/7f7cc85ca3f2846f1752939211cac30f to your computer and use it in GitHub Desktop.
Workbox cli config
const fs = require('fs');
const path = require('path');
const loadJsonFile = require('load-json-file');
const dotNext = path.resolve(__dirname, '.next');
const stats = loadJsonFile.sync(`${dotNext}/build-stats.json`);
const buildId = fs.readFileSync(`${dotNext}/BUILD_ID`, 'utf8');
const entries = Object.keys(stats).reduce(
(agg, src) =>
// /.next/app.js
Object.assign(agg, {
[`.next/${src}`]: `/_next/${stats[src].hash}/${src}`,
}),
{}
);
module.exports = {
globDirectory: '.',
globPatterns: Object.keys(entries)
.map(k => `./${k}`)
.concat(['./.next/bundles/**/*.js', './.next/chunks/**/*.js']),
clientsClaim: true,
skipWaiting: true,
swDest: `${dotNext}/sw.js`,
globIgnores: [
'.next/*.js',
'./workbox-cli-config.js',
'.next/dist/**/*',
'*.LICENSE',
],
modifyUrlPrefix: Object.assign({}, entries, {
'.next/bundles/pages/index.js': `/_next/${buildId}/page/`,
'.next/bundles/pages': `/_next/${buildId}/page`,
'.next/chunks': `/_next/${buildId}/webpack/chunks`,
}),
runtimeCaching: [
{
urlPattern: /^https:\/\/magicleap.com\/assets\/fonts\//g,
handler: 'cacheFirst',
},
{
urlPattern: /\.(gif|png|gltf|bin|jpe?g|svg|ico)$/i,
handler: 'cacheFirst',
},
{
urlPattern: /\.js$/i,
handler: 'cacheFirst',
},
{
urlPattern: /\/sw\.js$/g,
handler: 'networkOnly',
},
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment