Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable .babelrc inheritance

Tags:

babeljs

How do I force babel NOT to look at the parent directory for .babelrc?

  • I have two .babelrc files: ./a/.babelrc and ./a/example/.babelrc.
  • I am running babel in ./a/example path.
  • ./a/.babelrc defines a plugin “lodash".
  • I do not want to use this plugin when executing babel in ./a/example

I have tried setting ./a/example/.babelrc to:

{
    "stage": 0,
    "plugins": []
}

However, running babel in ./a/example path still uses "lodash" plugin.

$ pwd
/a/example
$ cat ./.babelrc
{
    "stage": 0,
    "plugins": []
}
$ cat ./../.babelrc
{
    "stage": 0,
    "plugins": [
        "lodash"
    ]
}
$ babel ./src/
Error: ENOENT: no such file or directory, scandir '/a/node_modules/babel-plugin-lodash/node_modules/lodash'
    [..]
$ babel --babelrc ./.babelrc ./src/
Error: ENOENT: no such file or directory, scandir '/a/node_modules/babel-plugin-lodash/node_modules/lodash'
    [..]
like image 228
Gajus Avatar asked Sep 12 '15 15:09

Gajus


People also ask

Do I need a Babelrc file?

babelrc would be useful if you want to run certain transformations / plugins on a subset of files /directories. Maybe you have 3rd party libraries that you don't want to be transformed/changed by babel.

What is a .babelrc file?

The . babelrc file is your local configuration for your code in your project. Generally you would put it in the root of your application repo. It will affect all files that Babel processes that are in the same directory or in sibling directories of the . babelrc .


1 Answers

There is an undocumented property called breakConfig. Set breakConfig to true to disable config inheritance.

This behaviour is going to change in 6.x. In 6.x Babel will break on the first .babelrc it finds. extends property is going to be used to explicitly name other .babelrc files to inherit from.

like image 88
Gajus Avatar answered Oct 21 '22 12:10

Gajus