wilk / microjob

A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
https://wilk.github.io/microjob/
MIT License
2.02k stars 47 forks source link

Single file build #46

Closed yovanoc closed 5 years ago

yovanoc commented 5 years ago

Hello,

I'm working on a big project in typescript and microjob could help me a lot, I already implements the things I have to put on worker threads and it's a huge improvement while I'm testing this in dev mode.

But the problem is that the production mode is going through webpack to build a single final js file to run with node. But for microjob I see that we need this .js file in the node_modules.

So I ask if there is a way to concat files, or if you are considering this for futures versions?

Really good job and thanks for this lib otherwise

manuel-di-iorio commented 5 years ago

In your final build, the worker.js file must remains separated as a single file. See if you can ignore that file from the build step and directly copy it into your destination folder.

yovanoc commented 5 years ago

that's not what I meant. I have to get a SINGLE final js build, not the js and the worker.js.

I hope you planned that

wilk commented 5 years ago

Hi @yovanoc,

thanks for reporting the issue and sorry for the late response. Currently, it's not possible to produce a single file build with microjob. However, this feature could be included in future releases.

I'm flagging this as a feature-request 👍

manuel-di-iorio commented 5 years ago

@wilk what do you think of using new Worker("executor_string", { eval: true }) ? Is this a vialable solution for you?

The worker code would still stay in a separated file for best practice, but exported as string, so that the goal of a single file build will be achieved:

module.exports = `
const { parentPort } = require('worker_threads')
parentPort.on('message etc...
wilk commented 5 years ago

@manuel-di-iorio Yes, passing directly the blob should work. Would you like to submit a PR?

yovanoc commented 5 years ago

Blob does not work on nodejs, right?

wilk commented 5 years ago

Close with release v0.7.0 🎉 Thank for your contribution @yovanoc !