w_lpz
w_lpz

Reputation: 613

Configuring for babel.config.js

I'm relatively new to Expo and React Native. Have been facing problems in using absolute paths while importing the modules. Was reading on how to implement this plugin but I am unable to use it properly since it has only instructions for .babelrc. I did almost everything found on different threads regarding this but still, I am unable to use it properly. In my expo project, I also do not have any .babelrc file instead I have babel.config.js file.

I am trying to convert this code for .babelrc:

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source",
        ["module-resolver", {
          "root": ["./src"]
        }]
      ]
    }
  }
}

To this for babel.config.js:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

Thanks

Upvotes: 1

Views: 13605

Answers (1)

jdnichollsc
jdnichollsc

Reputation: 1569

Check the configuration:

.babelrc

{
  "extends": "./babel.config.js"
}

babel.config.js

module.exports = (api) => {
  api.cache(true)
  return {
    "env": {
      "development": {
        "plugins": [
          "transform-react-jsx-source",
          ["module-resolver", {
            "root": ["./src"]
          }]
        ]
      }
    },
    presets: ['babel-preset-expo']
  }
}

Upvotes: 3

Related Questions