Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use more than one Babel preset in a project?

I am developing a React-Native app, which was installed using Expo, that creates .babelrc config with this code:

{
    "presets": ["babel-preset-expo"],
    "env": {
        "development": {
            "plugins": ["transform-react-jsx-source"]
        }
    }
}

Recently I have encountered 2 other libraries that require the installation of other types of babel presets named: "react-native" and "flow".

Question: How can I merge 3 presets?

like image 609
Eduard Avatar asked Oct 25 '17 16:10

Eduard


People also ask

What is Babel preset used for?

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

How do I add Babel?

Simply add a "scripts" field to your package. json and put the babel command inside there as build . This will run Babel the same way as before and the output will be present in lib directory, only now we are using a local copy. Alternatively, you can reference the babel cli inside of node_modules .

What should be in Babelrc?

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 .

What is a Babel plugin?

Babel is a JavaScript compiler Transform syntax. Polyfill features that are missing in your target environment (through a third-party polyfill such as core-js) Source code transformations (codemods) And more!


1 Answers

add them as items to the array of presets

{
    "presets": ["babel-preset-expo","react-native","flow"]
    "env": {
        "development": {
            "plugins": ["transform-react-jsx-source"]
        }
    }
}
like image 118
Jay Lane Avatar answered Oct 18 '22 20:10

Jay Lane