forked from external-repos/squoosh
Service Worker and Web Worker workarounds
This commit is contained in:
13
src/index.ts
13
src/index.ts
@@ -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)';
|
||||
|
||||
Reference in New Issue
Block a user