Giter Club home page Giter Club logo

Comments (6)

juddey avatar juddey commented on June 2, 2024 1

Heres my full babel.config.js:

No conditionals and just the couple of plugins you see at the bottom of the plugins array.

module.exports = function (api) {
  api.cache(true)
  return {
    presets: [
      'module:metro-react-native-babel-preset',
      'module:react-native-dotenv',
      '@lingui/babel-preset-react'
    ],
    plugins: [
      [
        'babel-plugin-root-import',
        {
          paths: [
            {
              rootPathPrefix: '~',
              rootPathSuffix: 'src/'
            },
            {
              rootPathPrefix: '#',
              rootPathSuffix: 'Tests/'
            }
          ]
        }
      ],
      ['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
      'macros'
    ]
  }
}

from babel-plugin-root-import.

brigand avatar brigand commented on June 2, 2024 1

@juddey thanks for the help. Updated the README.

from babel-plugin-root-import.

juddey avatar juddey commented on June 2, 2024

Hey @brigand, here's a config with a babel.config.js and the latest version of React-Native (0.57).
RN 56+ uses webpack 4 so I wonder if this renders the "env plugins array" redundant now...? I've never heard of the 'env plugins array' and I've been doing RN for about a year. Anyway, this works a treat for me.

I'll PR something up with the below if I haven't misunderstood the problem. Let me know.

    plugins: [
      [
        'babel-plugin-root-import',
        {
          paths: [
            {
              rootPathPrefix: '~',
              rootPathSuffix: 'src/'
            },
            {
              rootPathPrefix: '#',
              rootPathSuffix: 'Tests/'
            }
          ]
        }
    ]
]

from babel-plugin-root-import.

brigand avatar brigand commented on June 2, 2024

Babel 6 had a special way to define config for different NODE_ENV values within a JSON file. If react-native is on Babel 7 (where the babel.config.js file was introduced), I'm good with just giving Babel 7 instructions.

Is there any other babel-related code in your project, or conditionals in the babel.config.js file?

from babel-plugin-root-import.

juddey avatar juddey commented on June 2, 2024

@brigand No probs! You beat me to the PR though. 😄 Have a great day!

from babel-plugin-root-import.

joshuapinter avatar joshuapinter commented on June 2, 2024

We switched to using babel-plugin-module-resolve instead.

I have it working just fine on React Native 0.56.1:

package.json

"devDependencies": {
  "babel-plugin-module-resolver": "3.2.0"
}

.babelrc

{
  "plugins": [
    [ "module-resolver", { "root": ["./src"] } ]
  ]
}

index.android.js

import Constants from "Constants";

from babel-plugin-root-import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.