UNPKG

@dr.pogodin/react-utils

Version:

Collection of generic ReactJS components and utils

13 lines 1.23 kB
/** * Initialization of client-side environment. *//* global window */import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo.js";const buildInfo=getBuildInfo();// TODO: Should be moved into buildInfo module? if(process.env.NODE_ENV!=="production"){// eslint-disable-next-line no-console console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\"");// eslint-disable-next-line no-underscore-dangle window.__DEV_BUILD_INFO__=BUILD_INFO}/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */const{useServiceWorker}=buildInfo;if(useServiceWorker){const{navigator}=window;if("serviceWorker"in navigator){window.addEventListener("load",()=>{void(async()=>{try{// Note: no matter the "publicPath", we want to serve the service worker // from the web app root, to allow it control any and all pages of the // web app (otherwise, it will be restricted to the scope of its path). // The server takes it into account. const reg=await navigator.serviceWorker.register("/__service-worker.js");// eslint-disable-next-line no-console console.log("SW registered:",reg)}catch(err){// eslint-disable-next-line no-console console.log("SW registration failed:",err)}})()})}} //# sourceMappingURL=init.js.map