axeldelafosse / expo-next-monorepo-example

Create a universal React app using Expo and Next.js in a monorepo

Home Page:https://expo-next-monorepo-example.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

example of path alias in the project?

RazaShehryar opened this issue · comments

Hi,

I was wondering if there's any example of using path aliases in the project?

I have been using path aliases in my standalone expo project. It was working fine and I just had to configure tsconfig.json and babel.config.js in order to make them work. However, I am not sure how we can use path aliases in such a project structure?

Isn’t everything just in the app folder

No, it isn't. I was actually expecting a babel config file just like we have in expo or react native cli project in the app folder where you can define the paths. Right now I have created a tsconfig.json in app folder and defined paths in it but that's just for the VS code, right? You also need to define the paths separately in the babel file. Do I need to do that by going to expo folder and then making change in the babel config file (same for the nextjs)?

Each package you add in packages should be installed into your next and expo apps, such that you can import from ‘app/some-import’ via each app’s package.json.

For the expo app, you can add your own aliases in the Babel config if you want.

For the Next.js app, if you want import aliases, just add them to the tsconfig of the next folder.

https://nextjs.org/docs/advanced-features/module-path-aliases

you may need to add experimental.externalDir = true to your next config

@RazaShehryar Do you have an example on why you need paths instead of creating a new package in packages?

If you were going to use paths, I would only use them within a package - not across packages (as now your just doubling up on the functionality the monorepo provides).