-
I tried adding I also tried the following: // src/routes/+layout.svelte
<script lang=ts>
onMount(() => {
if (browser) {
const worker = new Worker('../lib/client/workers/indexedDB');
}
});
</script> and that also fails. I was able to make it work only by adding it to the static folder like so: Any ideas if there's a better way to do it with TypeScript if possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There's a feature in Vite.js that allows you to import workers and it'll instantiate them for you. For anyone who doesn't know, this is how: // hooks.client.ts
import MyWorker from '$lib/MyWorker?worker';
const myWorker = new MyWorker;
myWorker.postMessage('hello world to worker!') Thank you. |
Beta Was this translation helpful? Give feedback.
There's a feature in Vite.js that allows you to import workers and it'll instantiate them for you. For anyone who doesn't know, this is how:
Thank you.