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?
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.
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.
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 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.
.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"
]
}
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
.
.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-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With