onejs / one

❶ One is a new React framework - target web and native with a single Vite plugin and fully shared code, so you can ship cross-platform nearly as easy as single-platform.
https://onestack.dev
Other
3.36k stars 67 forks source link

one shouldn't depend on process.env.TAMAGUI_TARGET to detect native vs web. #252

Open prabirshrestha opened 6 days ago

prabirshrestha commented 6 days ago

I'm trying to use react-native-paper without tamagui but seems color-scheme package depends on TAMAGUI_TARGET for detecting native vs web.

I see there are other packages depending on it too. https://github.com/search?q=repo%3Aonejs%2Fone%20TAMAGUI_TARGET&type=code.

Should it instead have ONE_TARGET?

In the meantime how can one explicitly set TAMAGUI_TARGET in vite.config.ts so it works with web and iOS/android.

natew commented 5 days ago

We actually compile that away during build and use platform-specific file extensions in the output instead, so it shouldn't actually depend on that.

Is there some bug you're seeing? You can generally use isWeb or Platform.OS from react-native to detect platforms.

prabirshrestha commented 5 days ago

If isWeb works that it should be ok as long as it has dead code elimination so unnecessary js doesn't get loaded. I did find using TAMAGUI_TARGET a bit weird hence the issue.

natew commented 3 days ago

For dead code elimination we set environment variables, but we need more testing around it. I documented it here:

https://onestack.dev/docs/environment