-
Notifications
You must be signed in to change notification settings - Fork 96
Conversation
trivago#35 based on the changes suggested in that PR but apparently not further evaluated, this change should do what is required, even without all the steps in between mentioned here https://github.com/trivago/parallel-webpack/pull/35/files/bbdc8ffa14a2aa81adcdf5e1b5a5f1b951ffd215#r108773189 process.argv is in several locations overwritten by the args passed to the initial run.js and therefore always contain the required args so we just need to filter them, adjust them to kv pairs and then reduce them to an object to be passed as the env object
@pago could you check this out please? :) |
Very elegant solution but is it sufficient? Most command line tools accept varying syntaxes such as Might be safer to parse the |
i did not think about that one, let me try this real quick ;) |
better? :D |
Looks good now. I'd like to give it a quick test run before merging. |
Hi, I'm using ES6 in webpack.config.babel.js, seems parallel-webpack can parse ES6 but I need to do the following workaround in else if (typeof config === 'object' && config.default) {
return config.default(require('minimist')(process.argv, { '--': true }).env || {});
} |
@evisong i think my change should do? |
@pago if you feel lazy, clone this and test a basic config for the function support: |
What do you mean exactly? At trivago, we write webpack configs in ES6 but there's always a bootstrapping code that does the following:
However, if webpack is capable of handling |
src/loadConfigurationFile.js
Outdated
var config = require(configPath); | ||
if (typeof config === 'function') | ||
return config(require('minimist')(process.argv, { '--': true }).env || {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Unnecessary code duplication.
- Wrong code. There are 4 different permutations for function/object and default/no default.
- Split this function. It's too long already.
It should be refactored along these lines:
var configModule = require(configPath);
var configDefault = configModule && configModule.__esModule ? configModule.default : configModule;
var config = typeof configDefault === 'function' ? callConfigFunction(configDefault) : configDefault;
return config;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
babel sets the __esModule i guess?
ill adjust it a bit in a moment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took me a bit to remember that the es module export can be an object too ^^
not sure if you like the way i split the methods
Thanks @Robbilie ! I've added a test case (now that we can do that). Works nicely. :) |
#35
based on the changes suggested in that PR but apparently not further evaluated, this change should do what is required, even without all the steps in between mentioned here https://github.com/trivago/parallel-webpack/pull/35/files/bbdc8ffa14a2aa81adcdf5e1b5a5f1b951ffd215#r108773189
process.argv is in several locations overwritten by the args passed to the initial run.js and therefore always contain the required args so we just need to filter them, adjust them to kv pairs and then reduce them to an object to be passed as the env object