davestewart / alias-hq

The end-to-end solution for configuring, refactoring, maintaining and using path aliases
https://davestewart.co.uk/projects/open-source/alias-hq/
MIT License
333 stars 12 forks source link

Is babel support planned? #56

Closed sweethuman closed 1 year ago

sweethuman commented 2 years ago

I use Expo with React Native and it uses babel and I was just wondering if support for babel was planned to be added in the future?

An article of how to manually set it up is here if you want to use it for reference: https://zohaib.me/using-path-aliases-in-react-native-typescript-created-with-expo/

davestewart commented 2 years ago

Funny you should say that!

I started writing a plugin for babel / react native just a couple of weeks ago.

Let me check your article and compare it against what I have right now, then I'll publish.

Thanks for the issue :)

davestewart commented 2 years ago

Meanwhile – this isn't checked against your article, but – does this work?

const { toObject } = require('../../utils')

// @see https://webpack.js.org/configuration/resolve/#resolvealias
function callback (name, config) {
  name = name.replace('*', '(.*)')
  const path = config.paths[0].replace('/*', '/\\1')
  return {
    name,
    path,
  }
}

module.exports = function (config, options) {
  return toObject(callback, config, options)
}
davestewart commented 2 years ago

OK, I've been battling with React Native the last few days to get this working, and it seems I finally have 😅

It seems the way that aliases can be written in tsconfig and the the way babel module resolver handles regexp paths can be just different enough that module resolution fails, but I think I've got it now.

Will hopefully publish something in the next day or so

davestewart commented 1 year ago

@sweethuman - OK, Babel support added!

I've tested it in a local React Native project and it seems to work OK.

It seems the only issue is that Metro's extra node modules configuration can be a little weird with Babel.

I don't yet know if this is a Babel or Metro issue. If you can shed any light on the topic I'll be all ears!

Let me know how this update works, anyway.

sweethuman commented 1 year ago

Thanks so much, never expected this to happen so soon. I haven't dealt with react native and aliases in so long, but I owe you one because I have to deal with something similar again! <3

davestewart commented 1 year ago

Great! Keep me in the loop