Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zackargyle
Created October 12, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackargyle/8d716b8438c678dfa79123a586284c4b to your computer and use it in GitHub Desktop.
Save zackargyle/8d716b8438c678dfa79123a586284c4b to your computer and use it in GitHub Desktop.
Sample of Pinterest Mweb service worker generation
/* Create a service worker for every locale to precache the locale bundle */
const ServiceWorkerConfigs = locales.reduce((configs, locale) => {
return Object.assign(configs, {
[`mobile-${locale}`]: Object.assign({}, BaseConfig, {
template: path.join(__dirname, 'swTemplates/mobileBase.js'),
cache: {
template: path.join(__dirname, 'swTemplates/mobileCache.js'),
precache: [
'vendor-mweb-.*\\.js$',
'entryChunk-mobile-.*\\.js$',
'entryChunk-webpack-.*\\.js$',
`locale-${locale}-mobile.*js$`,
'pjs-HomePage.*\\.js$',
'pjs-SearchPage.*\\.js$',
'pjs-CloseupPage.*\\.js$'
]
}
})
});
}, {});
// Add to webpack
plugins: [
new ServiceWorkerPlugin(BaseConfig, ServiceWorkerConfigs);
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment