GoogleChromeLabs/worker-plugin

Bundle workers in generated file instead of separate worker files?

GlenHughes opened this issue · 1 comments

Hey,

I'm trying to include the worker files within my webpack generated main.js file but separate worker files are being generated when I build. How do I go about getting webpack to include the worker file in the main bundle?

Code:
import Worker from "worker-plugin/loader?esModule!./assets/worker.js"

// within my class...
const myWorker = new Worker(Worker, { type: "module" })

But rather than being included within the generated main.js file, I end up with a file generated i.e. 0.94ae570e433fac85eb17.worker which is fetched.

Any help would be appreciated!

Resolved this by using Webpack's worker loader: https://webpack.js.org/loaders/worker-loader/ which supports inline which converts the worker to a blob and includes within the bundle as a whole.