Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

config instead of configPath #83

Open
SassNinja opened this issue Aug 8, 2018 · 6 comments
Open

config instead of configPath #83

SassNinja opened this issue Aug 8, 2018 · 6 comments

Comments

@SassNinja
Copy link

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

@jefe-spain
Copy link

@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.

@SassNinja
Copy link
Author

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
Copy link
Contributor

pago commented Aug 10, 2018

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.

@KevinEady
Copy link

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

@matteobad
Copy link

matteobad commented Dec 24, 2019

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
Copy link

lake2 commented Jul 28, 2021

same need + 1 .

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants