Permalink
Browse files

resolved service worker not registering

  • Loading branch information...
monsieurBoutte committed Feb 4, 2019
1 parent 23d444e commit 9f5b9472c7f0a8a79787bae4a933a2ff33ca5e8a
Showing with 11 additions and 69 deletions.
  1. +0 −16 config-overrides.js
  2. +0 −42 public/custom-service-worker.js
  3. +1 −1 src/customServiceWorker.js
  4. +2 −2 src/index.js
  5. +8 −8 src/serviceWorker.js
@@ -13,26 +13,10 @@ module.exports = function override(config, env) {
const workboxConfig = {
...defaultInjectConfig,
swSrc: path.join(__dirname, 'src', 'customServiceWorker.js'),
swDest: path.join(__dirname, 'public', 'custom-service-worker.js'),
importWorkboxFrom: 'local'
};
config = rewireWorkboxInject(workboxConfig)(config, env);
}

return config;
};

// module.exports = function override(config, env) {
// config.plugins = config.plugins.map(plugin => {
// if (plugin.constructor.name === 'GenerateSW') {
// return new WorkboxWebpackPlugin.InjectManifest({
// swSrc: path.join(__dirname, 'src', 'customServiceWorker.js'),
// swDest: path.join(__dirname, 'public', 'custom-service-worker.js')
// });
// }

// return plugin;
// });

// return config;
// };

This file was deleted.

Oops, something went wrong.
@@ -3,7 +3,7 @@ workbox.core.setLogLevel(workbox.core.LOG_LEVELS.debug);

workbox.core.setCacheNameDetails({
prefix: 'git-lyrics',
suffix: 'v1'
suffix: 'v2'
});

self.addEventListener('install', event => event.waitUntil(self.skipWaiting()));
@@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { StoreProvider } from 'easy-peasy';
import store from './configureStore';
import * as serviceWorker from './serviceWorker';
import registerServiceWorker from './serviceWorker';
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
import { Routes } from './routes';
import { theme } from './styles/custom-theme-style';
@@ -22,4 +22,4 @@ ReactDOM.render(
);

// Learn more about service workers in CRA: http://bit.ly/CRA-PWA
serviceWorker.register();
registerServiceWorker();
@@ -20,35 +20,35 @@ const isLocalhost = Boolean(
)
);

export function register(config) {
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return;
}

window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/customServiceWorker.js`;

if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);

// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit http://bit.ly/CRA-PWA'
'worker. To learn more, visit https://goo.gl/SC7cgQ'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
// Is not local host. Just register service worker
registerValidSW(swUrl);
}
});
}

0 comments on commit 9f5b947

Please sign in to comment.