Service Worker and Web Worker workarounds

This commit is contained in:
Jason Miller
2020-08-12 18:18:22 -04:00
parent e972f7225a
commit f2dcd6e246
2 changed files with 12 additions and 5 deletions

View File

@@ -1,18 +1,23 @@
declare module '@webcomponents/custom-elements';
// Patch Worker to ignore `importScripts("x.css")` generated by Parcel:
const W = self.Worker;
self.Worker = function (url: string | URL, options?: WorkerOptions) {
const code = `importScripts = (function(){return this.apply(self,[].slice.call(arguments).filter(function(x){return !/\\.css$/i.test(x)}))}).bind(importScripts)\nimportScripts(${JSON.stringify(url)})`;
return new W(URL.createObjectURL(new Blob([code], { type: 'text/javascript' })), options);
} as any as (typeof Worker);
function init() {
require('./init-app.tsx');
}
if (!('customElements' in self)) {
import(
/* webpackChunkName: "wc-polyfill" */
'@webcomponents/custom-elements').then(init);
import('@webcomponents/custom-elements').then(init);
} else {
init();
}
if (typeof PRERENDER === 'undefined') {
if (typeof process.env.PRERENDER === 'undefined') {
// Determine the current display mode.
let displayMode = 'browser';
const mqStandAlone = '(display-mode: standalone)';