Which bundler are you using? in Vite for example you could use https://vite.dev/guide/features.html#web-workers
const worker = new Worker(new URL('./worker.js', import.meta.url))
or
import MyWorker from './worker?worker&inline'
to create an inline worker.
With esbuild you can try this plugin
with Webpack is almost the same as Vite