Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bundle and embed a dedicated worker which uses libraries in a web application? #189

Open
SlimaniB opened this issue Sep 30, 2020 · 1 comment
Labels

Comments

@SlimaniB
Copy link

SlimaniB commented Sep 30, 2020

I am trying to integrate workerpool with a Reactjs app (CRA) but am having quite a few different issues depending on how I try to achieve it. Using it with the Node part is no problem but I think more info is needed on the "browser" side of the repos.

By looking around I found #43 where Jos was kind enough to provide a basic example (https://codesandbox.io/s/xz9jwnyvrw). Issue is, in a real app you probably won't have a simple function placed in index.js that does not need any external librairies

  1. How can I define a seperate worker using its own external librairies and use it in index.js? using var pool = workerpool.pool('/path/to/worker.js') then pool.exec('function') as suggested in another thread did not work

  2. Can workerpool used for the browser only be integrated in the way described here https://github.com/josdejong/workerpool/blob/master/examples/browser?

I would appreciate a realistic example of integrating workerpool with a React app, maybe by updating the codesandbox to use an imported worker with its own librairies?

@josdejong
Copy link
Owner

This is something I'm still struggling with, good question.

Unless Webpack has some smartness to do this magically for us, I think you'll have to have a second build script which creates a bunlde for the worker. Here is an example where you see this in action:

https://github.com/josdejong/workerpool/tree/master/examples/embeddedWorker

If anyone knows a better/easier way to do bunding and embedding of worker code I would love to hear!

@josdejong josdejong changed the title Reactjs integration How to bundle and embed a dedicated worker which uses libraries in a web application? Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants