mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(v2): Plugin for Offline/PWA support (#2205)
* implement PWA plugin * added pwa support for docusaurus website * moved sw registration to client module * moved compile function to webpack util * build sw using webpack and render pwa popup * implement @theme/PwaReloadPopup * update website sw to use modules * updated pwa readme * fix header lint errors * apply code formatting * cache files only for mobile, saveData, or installed pwa * added comments about clearing registrations * fixed prettier error * updated pwa README * fix README JS * move /blog => /blog/index.html logic to else branch * add `alwaysPrecache` option * updated docusaurus-plugin-pwa version * added pwa to using-plugins.md * review fixes * re-disable restricted-globals to use self in service worker * useless doc * Update packages/docusaurus-plugin-pwa/README.md Co-authored-by: Reece Dunham <me@rdil.rocks> * Update packages/docusaurus-plugin-pwa/README.md * update a bit pwa doc + minor refactors * minor refactors + add workbox debug mode * env PWA_ prefix * typo * minor refactor * fix file output * add serve:v2:ssl yarn command * minor pwa fixes * typo * add dynamic import comment in SW * comment * let the PWA plugin implement its reload popup on his own * pwa: add Joi options validation * pwa plugin should have its own webpack/babel custom setup * PWA: - debug logs - better SW params system - offline mode activation strategies - docs * add pwa install gif * pwa: popup -> reloadPopup + minor refactors * fix process.env reading + better debug log * minor fixes * minor changes * minor changes Co-authored-by: slorber <lorber.sebastien@gmail.com> Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> Co-authored-by: Reece Dunham <me@rdil.rocks>
This commit is contained in:
parent
46f794b2ba
commit
9b3da59886
29 changed files with 1508 additions and 45 deletions
24
website/src/sw.js
Normal file
24
website/src/sw.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {registerRoute} from 'workbox-routing';
|
||||
import {StaleWhileRevalidate} from 'workbox-strategies';
|
||||
|
||||
export default function swCustom(params) {
|
||||
if (params.debug) {
|
||||
console.log('[Docusaurus-PWA][SW]: running swCustom code', params);
|
||||
}
|
||||
|
||||
// Cache responses from external resources
|
||||
registerRoute((context) => {
|
||||
return [
|
||||
/graph\.facebook\.com\/.*\/picture/,
|
||||
/netlify\.com\/img/,
|
||||
/avatars1\.githubusercontent/,
|
||||
].some((regex) => context.url.href.match(regex));
|
||||
}, new StaleWhileRevalidate());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue