NuxtN
Nuxt14mo ago
5 replies
thorne51

Worker env access

I'm building a web worker to post activity tracking to our API, although it doesn't seem like the worker is getting access to any of my environment variables. Some context:
- Worker is stored in /assets/js/activity.worker.js
- Worker is exposed via plugin which imports worker using suffix import ActivityWorker from '@/assets/js/activity.worker?worker
-
import.meta.env
has the following value in worker:
{
    "BASE_URL": "/_nuxt/",
    "DEV": true,
    "MODE": "development",
    "PROD": false,
    "SSR": false
}


Adding a VITE_CORE_API env variable to my
.env
file adds the value correctly to
import.meta.env
in the worker, although I would prefer not duplicating my existing CORE_API env var just for this.

Is there any other way to get the env variable into my worker?
Was this page helpful?