diff --git a/routes/_utils/loadPolyfills.js b/routes/_utils/loadPolyfills.js new file mode 100644 index 0000000..b88ea95 --- /dev/null +++ b/routes/_utils/loadPolyfills.js @@ -0,0 +1,17 @@ +import { + importURLSearchParams, + importIntersectionObserver, + importRequestIdleCallback, + importIndexedDBGetAllShim, + importDialogPolyfill +} from './asyncModules' + +export function loadPolyfills() { + return Promise.all([ + typeof URLSearchParams === 'undefined' && importURLSearchParams(), + typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), + typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), + !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), + typeof HTMLDialogElement === 'undefined' && importDialogPolyfill() + ]) +} \ No newline at end of file diff --git a/templates/main.js b/templates/main.js index 5c6ede6..5fd1315 100644 --- a/templates/main.js +++ b/templates/main.js @@ -1,23 +1,9 @@ import { init } from 'sapper/runtime.js' import { offlineNotifiction } from '../routes/_utils/offlineNotification' import { serviceWorkerClient } from '../routes/_utils/serviceWorkerClient' +import { loadPolyfills } from '../routes/_utils/loadPolyfills' -import { - importURLSearchParams, - importIntersectionObserver, - importRequestIdleCallback, - importIndexedDBGetAllShim, - importDialogPolyfill -} from '../routes/_utils/asyncModules' - -// polyfills -Promise.all([ - typeof URLSearchParams === 'undefined' && importURLSearchParams(), - typeof IntersectionObserver === 'undefined' && importIntersectionObserver(), - typeof requestIdleCallback === 'undefined' && importRequestIdleCallback(), - !IDBObjectStore.prototype.getAll && importIndexedDBGetAllShim(), - typeof HTMLDialogElement === 'undefined' && importDialogPolyfill() -]).then(() => { +loadPolyfills().then(() => { // `routes` is an array of route objects injected by Sapper init(document.querySelector('#sapper'), __routes__) }) \ No newline at end of file