teambit / envs

Component development environments for the Bit community
https://bit.dev/bit/envs
Other
63 stars 9 forks source link

Expo Web Support #135

Open alanrivetta opened 4 years ago

alanrivetta commented 4 years ago

Good day.

I would like to create a React project, precisely with Expo, which currently has Web support.

My question is: Is this work methodology compatible with Bit? Do I need a special compiler?

I am very grateful if you will guide me along the way.

Cheers

GiladShoham commented 4 years ago

@JoshK2 I believe you play a bit with expo, correct?

JoshK2 commented 4 years ago

@GiladShoham no, I did not try it. I'll check how the environments work with Expo and write here if it can be supported. But I think is just a template framework right? @alanrivetta And also I want to know what you want to try? For React Web development or IOS/Android?

alanrivetta commented 4 years ago

So far I have generated Mobile Applications with Expo. On the other hand, Web Applications with React and Create React App.

In this case I am looking to unify the code with Expo Web, where the biggest problem is dependency compatibility (Most don't work in Web and Mobile). But it can be solved.

As an example I use React Router, which has its separate Web and Mobile versions, so I unify them this way:

In the src/components/Router folder I have two files:

So by requiring the dependency (import {Router} from 'components/Router'), Expo will automatically import the file with the suffix of the platform it belongs to. (In this case it will always import the file "index.js" unless the Web platform requires it, there it will be "index.web.js")

Once this is done, we are able to integrate Web and Mobile code so that they coexist and behave according to the Platform used. Then, when compiling (yarn run build: web or yarn run build: android) it will generate the compilation, eliminating the code not required (for the other platforms)

What is not clear to me is how to perform this unification with Bit and its Envs, since when exporting a component to Bit, it compiles it, and I am not clear how it will behave and if it will continue to work as I need.

At the moment I do not have a proof of concept since I am analyzing the situation and I would like to know the opinion of the creators of Envs.

Thank you very much for your attention.

alanrivetta commented 4 years ago

Did my explanation help to clarify the picture? They need something more?

JoshK2 commented 4 years ago

@alanrivetta thanks for your explanation. @GiladShoham what do you think about the suffix support in Bit? The component main file needs to be changed in the building process depend on which target platform it will build, I'm right?

@alanrivetta did you try to use the Platform module option? https://reactnative.dev/docs/platform-specific-code#platform-module https://docs.expo.io/versions/latest/react-native/platform-specific-code/#platform-module

I know it's not the way you want, but it can be a good temporary solution.

alanrivetta commented 4 years ago

I understand it may be an interim solution.

In this way I understand that I would have to export my components in different builds, for each platform.

I am looking to be able to export only one component, and that it can continue having this characteristic of requiring modules depending on the platform on which it is running.