Skip to content
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

Configuring the babel loader is not possible when using babelrc file #543

Closed
stof opened this issue Mar 21, 2019 · 4 comments · Fixed by #544
Closed

Configuring the babel loader is not possible when using babelrc file #543

stof opened this issue Mar 21, 2019 · 4 comments · Fixed by #544
Labels

Comments

@stof
Copy link
Member

stof commented Mar 21, 2019

configureBabel currently has 2 arguments:

  • a mandatory callback altering the Babel config
  • an options argument allowing to configure some settings of the loader rule (excluding node modules or no for instance)

As the callback is incompatible with the usage of an external Babel config, this method throws an error when using it that way. But that means there is no way to configure options in such case.

@stof
Copy link
Member Author

stof commented Mar 21, 2019

my use case for using an external config file is that babel-eslint requires it

@stof
Copy link
Member Author

stof commented Mar 21, 2019

Oh, and of course, my project requires me to include some node modules in what gets processed by Babel (the material-components-web packages which use ES6 syntax in the modules), so I need the configuration of options.

@Kocal
Copy link
Contributor

Kocal commented Mar 21, 2019

Not related to your issue, but:

an options argument allowing to configure some settings of the loader rule (excluding node modules or no for instance)

Should we deprecate this functionality in favour of #509?

@stof
Copy link
Member Author

stof commented Mar 21, 2019

Well, I still like the include_node_modules option talking a list of modules and building the actual rule internally. It would be a shame to loose it.

@Lyrkan Lyrkan added the HasPR label Mar 21, 2019
weaverryan added a commit that referenced this issue Mar 29, 2019
…iguration (Lyrkan, weaverryan)

This PR was squashed before being merged into the master branch (closes #544).

Discussion
----------

Allow to call configureBabel with an external Babel configuration

This PR fixes #543 by allowing to call `Encore.configureBabel()` even if an external Babel configuration exists.

Basically:

* `null` (or any falsy value in reality, to keep it simple) is always allowed as a first argument
* a warning will be displayed if the first argument is a callback and something like a `.babelrc` file is detected
* a warning will be displayed if the second argument contains a non-whitelisted option (ie. not `includeNodeModules`/`exclude`) and something like a `.babelrc` file is detected

```js
// Allowed without any warning
Encore.configureBabel(null, {
  includeNodeModules: ['foo']
});

// Displays a warning and the
// callback is ignored
Encore.configureBabel(
  () => { /* ... */ }
);

// Displays a warning and the
// useBuiltIns option is ignored.
Encore.configureBabel(null, {
  useBuiltIns: 'foo',
  includeNodeModules: ['foo'],
});
```

Commits
-------

a9af955 Merge branch 'master' into configure-babel-optional-callback
ffe3054 Recommend null instead of false for the first parameter of configureBabel()
644d1ac Allow to call configureBabel with an external Babel configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants