question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Threads.js Bundling

See original GitHub issue

I have been thinking more about this and I realized that I don’t want to ask upstream-users of my library to bundle the workers from threads.js via webpack or parcel. It seems that there isn’t an accepted way to write a “library” using this (see https://github.com/andywer/threads.js/issues/211 and https://github.com/andywer/threads.js/issues/232#issuecomment-613159302) since you can’t get a single bundle easily. If I have this wrong, I’d love to know how to get this to work, but it seems that there isn’t an easy way to publish a library that uses threads.js without having upstream users handle the implicit code-splitting. Again, if I have this wrong, please let me know - despite the bundling, threads.js is far easier to understand/use!

I reverted to using the old web workers from an old release of GeoTIFF in my application: https://github.com/hubmapconsortium/vitessce-image-viewer/pull/160. In my testing via npm pack I don’t seem to have any issues with the bundling and it works well. I understand the ease of parcel as well as threads.js as opposed to using webpack/webworkers but I just wanted to leave this here for anyone else who might encounter this, or if changes are desired, to help start a roadmap for them.

CC: @PacoDu @constantinius

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
andywercommented, Jun 20, 2020

Hey there! I don’t know if you saw it already or if it’s still an urgent topic for you, but threads.js now supports inlining worker code using BlobWorker, so you can ship master and worker code together in a single module.

Only gotcha right now: When bundling you need to run webpack twice. First bundle the worker(s) and then run webpack again for the main entrypoint code.

0reactions
constantiniuscommented, Jun 26, 2020

Thanks, much appreciated

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic usage - Web worker meets worker threads
Bundle this module and you will obtain a stand-alone bundle that has its worker inlined. This is particularly useful for libraries using threads.js....
Read more >
andywer/threads.js: Make web workers & worker ... - GitHub
Use with the threads-plugin . It will transparently detect all new Worker("./unbundled-path") expressions, bundles the worker code and replaces the new Worker(.
Read more >
Seamless web workers & worker threads - threads.js
A vast number of people use webpack to bundle their code for front-end deployment. So how do we now make that code build...
Read more >
How to bundle worker_thread dependencies with webpack
So I'm wondering: How can I use worker_threads that reference modules in my project? node.js · webpack · worker-thread · node-worker-threads.
Read more >
Multithreading in JavaScript with Web Workers - LeanyLabs
The worker thread will return the results on completion and may ... Most modern web applications use WebPack to bundle all the javascript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found