-
Notifications
You must be signed in to change notification settings - Fork 449
Use workbox-cli to generate the service worker #5681
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| module.exports = { | ||
| // All navigation that's not in the cache will respond the entry for /index.html. ("SPA" mode) | ||
| navigateFallback: '/index.html', | ||
| // Cleanup the caches from old workbox installations. This isn't useful | ||
| // for us _now_ but this can be later for future versions. | ||
| cleanupOutdatedCaches: true, | ||
| // Our biggest asset in production is currently 1.34MB. Therefore 2MB in | ||
| // production looks sensible (this is the default too). | ||
| // If it's not cached then index.html is answered instead because of | ||
| // navigateFallback, then everything it's broken. | ||
| // In development we want to use a higher limit so that we don't hit the | ||
| // limit. This isn't normally used but can be used when debugging the | ||
| // service worker. | ||
| maximumFileSizeToCacheInBytes: | ||
| process.env.NODE_ENV === 'development' ? 10 * 1024 * 1024 : 2 * 1024 * 1024, | ||
| // Don't append cache busting query strings to files whose filenames contain | ||
| // hashes from the bundler. | ||
| dontCacheBustURLsMatching: /\b[0-9a-f]{20}\./, | ||
| // All scripts, including imported scripts, will be requested bypassing | ||
| // HTTP cache, to determine if an update is needed, because we use | ||
| // `updateViaCache: none` during the register. That's why we don't need to | ||
| // use a hash or version in this file name. | ||
| // For more information and background, see: | ||
| // - discussion in https://github.com/w3c/ServiceWorker/issues/106 | ||
| // - chrome update in https://developer.chrome.com/blog/fresher-sw/ | ||
| // - step 8.21 in https://w3c.github.io/ServiceWorker/#update-algorithm | ||
| importScripts: ['/service-worker-compat.js'], | ||
| navigateFallbackDenylist: [ | ||
| // requests to docs and photon example pages shouldn't be redirected to | ||
| // the index file as they're not part of the SPA | ||
| /^\/docs(?:\/|$)/, | ||
| /^\/photon(?:\/|$)/, | ||
| // Allow navigating to source maps. This is not necessary, but it is | ||
| // more developer friendly. | ||
| /^\/[^/?]+\.map$/, | ||
| // While excluding the service worker file isn't necessary to work, it's | ||
| // convenient that we can just access it from a browser. | ||
| /^\/sw\.js/, | ||
| ], | ||
| globDirectory: 'dist', | ||
| globPatterns: ['**/*'], | ||
| globIgnores: [ | ||
| // exclude user docs and photon from the cache | ||
| 'docs/**', | ||
| 'photon/**', | ||
| // exclude also the netlify-specific files that aren't actually served | ||
| // because this would fail the service worker installation | ||
| '_headers', | ||
| '_redirects', | ||
| // do not cache source maps | ||
| '**/*.map', | ||
| // nor the service worker imported script | ||
| 'service-worker-compat.js', | ||
| ], | ||
| // This is the service worker file name. It should never change if we want | ||
| // that the browser updates it. If this changes it will never be updated | ||
| // and the user will be stuck with an old version. | ||
| swDest: 'dist/sw.js', | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we need to call build-sw at the end because it depends on the webpack outputs, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right.