-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom ServiceWorker config #2237
Comments
What specifically would you like to be able to change? |
Currently I use I would expect to be able to define a |
@gnhuy91 so we are most likely not going to let you define your own config, but if you let us know what you are trying to achieve, we can consider adding support for specific options. |
Thanks, this is my current config: module.exports = {
swFilePath: 'build/service-worker.js',
stripPrefix: 'build/',
staticFileGlobs: [
'build/*.html',
'build/manifest.json',
'build/static/**/!(*map*)',
],
dontCacheBustUrlsMatching: /\.\w{8}\./,
navigateFallback: 'index.html',
runtimeCaching: [{
urlPattern: /https?:\/\/fonts.+/,
handler: 'fastest',
}, {
urlPattern: /https?:\/\/images.+/,
handler: 'fastest',
}],
}; Currently I only need to define some |
@Timer I just updated to the newest version, and tried to use the new PWA support as well, and there seems to be an issue with Firebase auth. Firebase auth uses the |
cc @jeffposnick on suggestions for how a tool striving to have minimal configuration could handle this. |
There are definitely use cases where folks might want something other than the default configuration. I tried to choose default configuration options that are, in general safe, with the understanding that developers who need to make changes will go through the I don't know how common it is for servers to use the {
navigateFallbackWhitelist: [/^(?!\/__)/]
} would account for them. Doing so would be unlikely to break anyone, and it would accommodate some of the folks upthread without forcing them to As for the questions about configuring |
I was really tempted to come here to support being able to configure |
I'm going to have to agree with Jeff that for now ejecting is probably the best call for customizing runtimeCaching. There are a few too many permutations for how we've seen folks use the option to provide a flexible alternative that would be as useful. |
I’ll close this for now, as we’re not going to do it soon, but we might consider this at some point in the future. For now you’d either need to eject, or add your own custom build step |
Just for reference, here's how I've implemented the extra build step for the app to work with firebase auth: const fs = require('fs')
fs.readFile('build/service-worker.js', 'utf8', (error, data) => {
if (error) {
return console.log(error)
}
const result = data.replace(/isPathWhitelisted\(\[\]/g, 'isPathWhitelisted([/^(?!\\/__)/]')
fs.writeFile('build/service-worker.js', result, 'utf8', (error) => {
if (error) {
return console.log(error)
}
})
}) EDIT: This is not needed now, see below. |
I've discovered that the issue that @dsgh mentioned is present in other projects such as https://github.com/Polymer/polymer-cli/issues/290, and the default |
The Firebase issue should be fixed in 1.0.6. |
Does this work right now? I see this in my
(This is a completely new app). I serve this with a node server like so
But when I hit
I want to use this to bypass the service worker on another route, but I expected the above to work out of the box. |
Any plans on allowing this soon? I've completely disabled the auto generated service worker as it caches some URLs it really shouldn't and I can't exclude them, without ejecting. |
This can be done with react-app-rewired. In module.exports = function override(config, env) {
const swPrecacheConfig = config.plugins.find(
plugin => plugin.constructor.name === "SWPrecacheWebpackPlugin"
);
// Prevent some URLs from being cached by the service worker
swPrecacheConfig.options.navigateFallbackWhitelist = [
/^(?!\/(__|privacy-policy|terms-of-service)).*/
];
return config;
}; |
1.0.0
added Progressive Web App support, is it possible to support custom config in near future? I really don't want toeject
just to add runtime caching configs 😄The text was updated successfully, but these errors were encountered: