Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the location of .babelrc file?

Tags:

babeljs

I have installed Babel and found out that in order to compile JSX, .babelrc file needs to be changed? Where is the file located? I was looking in the babel-preset, babel, babel-jsx folders and so on, but could not find it? Should it be created manually?

like image 345
user3104270 Avatar asked Feb 14 '16 11:02

user3104270


People also ask

Where is .babelrc in react native?

You have to add it to your . babelrc in your react native folder in your node_modules folder. This file: react-native/packager/react-packager/. babelrc.

Where do I put Babel presets?

Within a Babel config, if the preset is on npm, you can pass in the name of the preset and Babel will check that it's installed in node_modules already. This is added to the presets config option, which takes an array. Otherwise, you can also specify a relative or absolute path to your presets.

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.

Where is Babel config JS react?

Where can I find the babel configuration of a non ejected application made with create-react-app ? It's in the Webpack config of the react-scripts/config directory.


3 Answers

.babelrc is never auto created. You must go to the root directory of your project. Create a file - touch .babelrc, open the file and enter the babel settings here, then save. If you are following https://babeljs.io/blog/2015/10/31/setting-up-babel-6, Setting up Babel 6 and installed all the plugins and presets as stated, this may help.

{
  "presets": [
    "es2015",
    "env",
    "react",
    "stage-2"
  ]
},

{
  "plugins": [
    "transform-es2015-arrow-functions",
    "check-es2015-constants",
    "transform-es2015-block-scoping"
  ]
}
like image 186
MelH Avatar answered Sep 21 '22 15:09

MelH


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.

like image 44
loganfsmyth Avatar answered Sep 22 '22 15:09

loganfsmyth


.babelrc could potentially exist in several places in the node tree.

The project root folder would see to be most likely. The babel config could also be specified within package.json under "babel:" {...}

Lookup behavior

Babel will look for a .babelrc in the current directory of the file being transpiled. If one does not exist, it will travel up the directory tree until it finds either a .babelrc, or a package.json with a "babel": {} hash within.

Use "babelrc": false to stop lookup behavior.

See https://github.com/insin/babel-plugin-react-html-attrs/blob/master/README.md and Look Up behavior-

like image 33
kvista Avatar answered Sep 23 '22 15:09

kvista