I'm intending to use web worker inside my Node.js application for some concurrent tasks. However since the 'webworker-threads'
module follows the implementation of HTML5 web worker, requiring Nodejs modules like require("fs")
inside web worker does not work. importScripts()
can load js files but I would like a functionality inside the web worker so that I can require
npm-installed modules. Is there a workaround for that?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
author of webworker-threads here. Thank you for using the module!
There is a default
native_fs_
object with thereadFileSync
you can use to read files.Beyond that, I've mostly relied on onejs to compile all required modules in
package.json
into a single JS file forimportScripts
to use, just like one would do when deploying to a client-side web worker environment. (There are also many alternatives to onejs -- browserify, etc.)Hope this helps!