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

Allow for plugins to be declared as objects #9635

Open
gurs1kh opened this Issue Mar 4, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@gurs1kh
Copy link

gurs1kh commented Mar 4, 2019

Feature Request

Is your feature request related to a problem? Please describe.
No...well, mainly readability if that counts

Describe the solution you'd like
I think it would be good to allow for a user to declare an object for plugins rather than arrays. This is mainly because when it comes to using several plugins with a lot options, it often becomes harder to read the declarations.
Here's how I'd purpose the optional object be handled:

Something like this:

module.exports = function(api) {
  api.cache(true);
  return {
    ...
    plugins: [
      ['pluginA', {...}],
      ['pluginB', {...}],
      'empty-plugin',
    ],
    ...
  };
};

could be written as:

module.exports = function(api) {
  api.cache(true);
  return {
    ...
    plugins: {
      'pluginA': {...},
      'pluginB': {...},
      'empty-plugin': {},
    },
    ...
  };
};

Describe alternatives you've considered
I've considered just doing this:

module.exports = function(api) {
  api.cache(true);
  return {
    ...
    plugins: Object.entries({
      'pluginA': {...},
      'pluginB': {...},
      'empty-plugin': {},
    }),
    ...
  };
};

This shows how simple this would be to implement.

Teachability, Documentation, Adoption, Migration Strategy
I'm sure many users would prefer this way, especially when they have many plugins with many different options in their config.

In terms of documentation, I guess an additional sections could be added to the https://babeljs.io/docs/en/plugins page, which could be included with or after the Plugin Options sections. Something like:

You can also declare plugin options as an object:

{
  "plugins": {
    "pluginA": {},
    "pluginB": {},
    "pluginC": {}
  }
}
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Mar 4, 2019

Hey @gurs1kh! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.