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

Pass config directly to Node API #21

Closed
nwhite89 opened this issue Nov 29, 2016 · 5 comments
Closed

Pass config directly to Node API #21

nwhite89 opened this issue Nov 29, 2016 · 5 comments

Comments

@nwhite89
Copy link

Doing this would allow for a lot more freedom when it comes to configurations, for example depending on when mine is run my config slightly changes meaning that it needs to be a function that can be executed rather than simply required in which causes problems when coming to use this package.

@pago
Copy link
Contributor

pago commented Nov 30, 2016

Could you provide an example of what you mean? I'm not sure I fully understand your use case.

@nwhite89
Copy link
Author

nwhite89 commented Dec 1, 2016

Hey @pago so we are using Webpack's Node API rather than CLI, currently we are creating the configuration on the fly. The reason for this is that we are using Webpack behind an end-point to bundle files together the end-point then passes specific definition files.

Post A could be perhaps something like:

{
    'LIVE': true,
    'packages': {
        'jQuery': true,
        'Angular': true,
        'React': false
    }
}

Post B could be perhaps something like:

{
    'LIVE': true,
    'packages': {
        'jQuery': false,
        'Angular': false,
        'React': true
    }
}

Both examples are extremely crude but I hope you get the gist of the idea. The with this we call;

webpack(request.body, function (err, stats) {
    if (err) {
        res.body('error');
    } else {
        res.body('location of file');
    }
});

Now with parallel-webpack it looks like we can only provide a configuration file which would mean that we would need to generate the configuration as a file perhaps in a temp folder which isn't really ideal.

Thanks in advance

@pago
Copy link
Contributor

pago commented Dec 1, 2016

That's tricky because its unfortunately not generally possible. We can only do parallel builds because we start new processes and because the webpack configuration can contain class instances, it can't be serialized. As a result, we can't start different processes and pass the actual configuration around.

What we essentially do at trivago is to have the configuration configurable through the environment and CLI parameters (there's a bit more that influences the builds but that's the basic idea). So instead of passing a finalized configuration to webpack, we pass configuration to the webpack.config.js which then generates the right configurations for us (returning an array of configs). As far as I know, that is the only way to achieve parallel execution.

@nwhite89
Copy link
Author

nwhite89 commented Dec 2, 2016

@pago ok thank you I'll close this

@nwhite89 nwhite89 closed this as completed Dec 2, 2016
@fakalit
Copy link

fakalit commented Jun 23, 2017

another use case if you are using webpack with a task runner like gulp or broccoli, integration plugins modify webpack config on the fly before passing it to webpack's node API. if you want to replace webpack with parallel-webpack in a plugin, well, you can't 😄

would be nice if parallel config API has a similar API to webpack itself. switching between them would be easier.

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

No branches or pull requests

3 participants