Created
October 12, 2017 20:49
-
-
Save zackargyle/8d716b8438c678dfa79123a586284c4b to your computer and use it in GitHub Desktop.
Sample of Pinterest Mweb service worker generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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