Skip to content

What's the best way to add workers in SvelteKit? #9123

Answered by ioucyf
ioucyf asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@azern32
Comment options

Answer selected by eltigerchino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants