Skip to content

configFactory: support entry as an array #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
maxceem opened this issue Feb 1, 2018 · 4 comments
Closed

configFactory: support entry as an array #6

maxceem opened this issue Feb 1, 2018 · 4 comments

Comments

@maxceem
Copy link
Contributor

maxceem commented Feb 1, 2018

Providing entry value to configFactory as an array it's not supported.

What I did:

  • Call configFactory providing an array to entry:

    configFactory({
      entry: [
        'one entry',
        'second entry'
      ]
    })
    
  • In the resulting webpack config both for development and production environment I get:

    {
       entry: [
        'one entry',
        'second entry'
      ]
    }
    
  • Expected output for production is:

    {
      entry: {
        main: [
          'one entry',
          'second entry'
        ],
        polyfills, [
          'babel-polyfill',
          'nodelist-foreach-polyfill',
       ]
    }
    
  • and for development:

    {
      entry: {
        main: [
          'react-hot-loader/patch',
          'webpack-hot-middleware/client?reload=true',
          'one entry',
          'second entry'
        ],
        polyfills, [
          'babel-polyfill',
          'nodelist-foreach-polyfill',
       ]
    }
    
@birdofpreyru
Copy link
Collaborator

birdofpreyru commented Feb 1, 2018

@maxceem are you sure you don't override the entry config at your side, ocasionally?
Cause the code block that normalizes the entry config

const entry = _.isObject(o.entry)
? _.cloneDeep(o.entry) : { main: o.entry };
if (!entry.polyfills) entry.polyfills = [];
else if (!_.isArray(entry.polyfills)) {
entry.polyfills = [entry.polyfills];
}
entry.polyfills = _.union(entry.polyfills, [
'babel-polyfill',
'nodelist-foreach-polyfill',
]);

is supposed to support array values already.

@maxceem
Copy link
Contributor Author

maxceem commented Feb 1, 2018

@birdofpreyru yeah, I'm sure that I didn't override that.

The thing is, that _.isObject returns true for arrays https://lodash.com/docs/4.17.4#isObject.
Thus it assigns polyfills property to an array instead of creating a new object with array assigned to main.

@birdofpreyru
Copy link
Collaborator

Oh... Let's replace it with _.isPlainObject(..)? It will work correct for this case. Can you think about any corner case where it may fail?

@maxceem
Copy link
Contributor Author

maxceem commented Feb 1, 2018

Replacing with _.isPlainObject(..) sounds like a proper solution. I cannot imagine any reasonable value where it can fail.

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

No branches or pull requests

2 participants