Is it possible to use load webworkers?
See original GitHub issueIn the past I’ve used the web-worker loader in webpack, but with create-react-app, I get the no-webpack-loader-syntax
error.
Is there another way that you recommend to do this? I can’t find anything in your documentation about webworkers, and it seems there isn’t another way to load them in webpack.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:24 (6 by maintainers)
Top Results From Across the Web
Using Web Workers - Web APIs - MDN Web Docs
Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering ......
Read more >Is there some kind of load event for web-workers?
As per last comment, I'll wrote my suggestion as answer: You can make the worker emit a message when they're loaded, and you...
Read more >Optimized media loading using the Web Workers API
The Web Workers API helps to solve the decades-old issue of efficiently loading media into JavaScript-based web applications.
Read more >Understanding and Using Web Workers - CODE Magazine
A Web Worker script is loaded on demand, at run-time. Unlike other JavaScript files with which you've worked in the past that have...
Read more >Loading web workers using Webpack 5 · mmazzarolo.com
worker-loader is the pre-webpack-5 way to load web workers, ... you won't be able to load the following web worker: const myWorker =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, if anyone stumbles upon this thread, here’s a bit messy, but quick and easy way to get WebWorkers working.
npm install --save-dev react-app-rewired worker-loader lodash
config-overrides.js
file in the root directory of your application:MySomething.worker.js
:P.S. As a sidenote, a bit of feedback, as I’ve just began experimenting with create-react-app (having always created my own configurations before). I must say it feels that it kind of lost the second part of “convention over configuration” principle. That is, it almost entirely discarded the ability “to specify unconventional aspects of the application”. For example, I had to install the aforementioned react-app-rewired just to get my own module resolve paths and LESS support — being unable to configure such basic things was quite a surprise.
Based on the previous answers, I wrote a helper class to make things a bit easier when working with Web Workers in React.
The helper class looks like so:
Then, you write your worker code like this:
To create a Web Worker instance, write like so:
Using this method, you simply utilise the WebWorker helper class, and there’s no need for Webpack loaders or anything like that. It worked for me and solved my problems. Hopefully we won’t have to do workarounds like these in the future.