trivago/parallel-webpack

config instead of configPath

SassNinja opened this issue · 6 comments

Explain the problem

I build webpack configs dynamically based on user interaction (terminal prompt).
I can't and I don't wanna place each config as actual file in the project.
To build them all at once I put them in an array and use webpack's node api like this

const webpack = require('webpack');
const parallelWebpack = require('parallel-webpack');
const myConfigs = [
  {
    entry: { a: 'a.js' }
  },
  {
    entry: { b: 'b.js' }
  }
];

webpack(myConfigs, cb);

But when I try the same with webpack-parallel it throws an error

parallelWebpack(myConfigs, cb);

// => UnhandledPromiseRejectionWarning: TypeError: parallelWebpack is not a function

Same with parallelWebpack.run()

parallelWebpack.run(myConfigs, cb);

// => Could not load configuration file [object Object],[object Object]

I've found #11 which seems to refer to this problem but is now more than a year old.
Is there still no chance to use configs with parallel-webpack instead of configPaths?

If no I've to do without the performance benefits :/

Expected Behaviour

Behave similar to webpack's api

Actual Behaviour

Does not support configs as param

Steps to reproduce

Try to run parallel node api with configs as param

Provide your webpack config

Provide your Environment details

  • Node version: v8.11.3

  • Operating System: Mac OS X

  • webpack version: 4.16.4

  • parallel-webpack version: 2.3.0

@SassNinja Let me know if you find something useful. I'm looking for the same as you. That will allow to dynamically create configs to build or make the things even simpler.

Sure if I find something I'll let you know.

So far the only possibility that comes into my mind is emitting my dynamic configs as files (using node's fs), starting parallel-webpack and then removing the config files again.

But this feels like a bad workaround and would take away the performance benefit.
I think there's no way but adjusting the core of parallel-webpack itself.

pago commented

The problem here is passing complex objects (i.e. instances of classes - Webpack Plugins) to another process. Even if you change the core of parallel-webpack, it'll likely not work.

Webpack's config objects can't be serialized and node doesn't have threads which is why we're using forked processes and those don't have access to their parent processes context. Let me know if you do find a solution though. That'd be very interesting. I think there was some rather new library from Microsoft for multi-threading in node. Don't know if it'd work for this use case though.

Note: I'll mark this as "wontfix" since I don't think it can be fixed. If you do find a way, I'd love to integrate it.

Hi @SassNinja / anybody else trying to do this...

I ended up changing my architecture... Instead of the main script (which calls run()) generating the config object, move the object generation into a webpack.config.js that accepts arguments. These arguments are then passed to webpack.cofing.js via run() option argv.

Hope this helps

Hi, I know it's been a while, but I was facing the same problem. The documentation says the following:

You can specify any other option used in worker-farm

Then I looked up to the worker-farm docs and found out that it accepts the following options:

{
    workerOptions               : {}
  , maxCallsPerWorker           : Infinity
  , maxConcurrentWorkers        : require('os').cpus().length
  , maxConcurrentCallsPerWorker : 10
  , maxConcurrentCalls          : Infinity
  , maxCallTime                 : Infinity
  , maxRetries                  : Infinity
  , autoStart                   : false
  , onChild                     : function() {}
}

The workeOptions is the most interesting one. It allows you to customize all the parameters passed to child nodes. But when I tried o do so nothing went through.

Looking at the parallel-webpack source I saw the validate function witch is cleaning up the options based on schema.json. This is the part that filters out the workerOptions.

My question is why? If we could have these options available we could be able to pass some options down to the children, or am I missing something?
Thank you in advance. If it helps I could make a PR.

Merry Christmas ✨

lake2 commented

same need + 1 .

Can I pass config to parallel-webpack intead of config path?