web/satellite: fix access grant worker load for production builds

Change-Id: Ifdcf3b490c10f491ff861b0e7887ba0edfcbfd7f
This commit is contained in:
Vitalii 2023-06-07 16:42:55 +03:00
parent 58836834da
commit 4aafa7f043

View File

@ -44,8 +44,13 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => {
async function startWorker(): Promise<void> {
// TODO(vitalii): create an issue here https://github.com/vitejs/vite
// about worker chunk being auto removed after rebuild in watch mode if using new URL constructor.
// const worker = new Worker(new URL('@/utils/accessGrant.worker.js', import.meta.url));
const worker = new Worker('/static/src/utils/accessGrant.worker.js');
let worker: Worker;
if (process.env.NODE_ENV === 'development') {
worker = new Worker('/static/src/utils/accessGrant.worker.js');
} else {
worker = new Worker(new URL('@/utils/accessGrant.worker.js', import.meta.url));
}
worker.postMessage({ 'type': 'Setup' });
const event: MessageEvent = await new Promise(resolve => worker.onmessage = resolve);