feat(frontend): provide a corsworker for vite
This commit is contained in:
@@ -19,3 +19,15 @@ export class CorsWorker extends window.Worker {
|
||||
URL.revokeObjectURL(objectURL);
|
||||
}
|
||||
}
|
||||
|
||||
// Vite equivalent of the above CorsWorker to allow loading workers from a different origin
|
||||
export function WorkaroundWorker(workerUrl: string, options: WorkerOptions) {
|
||||
const js = `import ${JSON.stringify(new URL(workerUrl, import.meta.url))}`;
|
||||
const blob = new Blob([js], { type: 'application/javascript' });
|
||||
const objURL = URL.createObjectURL(blob);
|
||||
const worker = new Worker(objURL, { type: 'module', name: options?.name });
|
||||
worker.addEventListener('error', (e) => {
|
||||
URL.revokeObjectURL(objURL);
|
||||
});
|
||||
return worker;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user