GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

Bundle workers in generated file instead of separate worker files? #87

Closed GlenHughes closed 4 years ago

GlenHughes commented 4 years ago

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!

GlenHughes commented 4 years ago

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.