Paul Razvan Berg
Paul Razvan Berg

Reputation: 21440

How to extend a parent babel config?

With eslint, I can do this:

.eslintrc.js
packages/
  foo/
    .eslintrc.js
  bar/
    .eslintrc.js

Where the child .eslintrc.js looks like this:

{
  "extends": ["react-app", "../../.eslintrc.js"]
}

Can I do this with babel configuration files? I know about --root-mode=upward, but I don't think that helps here.

Upvotes: 1

Views: 4016

Answers (1)

Paul Razvan Berg
Paul Razvan Berg

Reputation: 21440

I figured it out thanks to this article: So What's New in Babel 7.

Since v7, you can add overrides to your configuration file:

//babel.config.js
module.exports = {
  presets: [ ... ],
    overrides: [
    {
      test: ["./packages/bar"],
      presets: ["@babel/preset-react"],
    },
  ],
}

Where:

  • test = the glob pattern to match a certain path in your repository
  • presets = the presets you want to add to your selective configuration (note that the default presets are preserved)

Upvotes: 2

Related Questions