From 4aafa7f04395c1fe115bb926762d1c0674511120 Mon Sep 17 00:00:00 2001 From: Vitalii Date: Wed, 7 Jun 2023 16:42:55 +0300 Subject: [PATCH] web/satellite: fix access grant worker load for production builds Change-Id: Ifdcf3b490c10f491ff861b0e7887ba0edfcbfd7f --- web/satellite/src/store/modules/accessGrantsStore.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/satellite/src/store/modules/accessGrantsStore.ts b/web/satellite/src/store/modules/accessGrantsStore.ts index 40fdfdd20..218e5344f 100644 --- a/web/satellite/src/store/modules/accessGrantsStore.ts +++ b/web/satellite/src/store/modules/accessGrantsStore.ts @@ -44,8 +44,13 @@ export const useAccessGrantsStore = defineStore('accessGrants', () => { async function startWorker(): Promise { // 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);