Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Forward file (web worker) in dependency to be statically available (not bundled) or change paths to confirm to bundle

$
0
0

My concrete Problem is also detailed here

I want to use a web worker defined in a dependency (I also only want to use it in this dependency) but I cannot find a way to load it as svelte-package -> vite messes up the pass and doesn't make the worker file available in the specified path

  1. create a svelte package that uses a web worker, i.e a component that uses something like import Worker from '$lib/workers/w.worker?worker'; in its script tag
  2. bundle that package using svelte-package
    • ❗ this replaces the import with a relative path: import Worker from '../workers/w.worker?worker';
  3. upload to npmjs or similar and add as dependency
  4. in the new project run npm run dev
    • ❗ this throws: ✘ [ERROR] Could not resolve "../workers/w.worker?worker"

similarly using the new Worker(new URL('$lib/workers/w.workers.mts', import.meta.url), { type: 'module' }); syntax results in the browser having a 404


Viewing all articles
Browse latest Browse all 1541

Trending Articles